我调试我的应用程序时出现sql语法错误

时间:2010-06-10 09:38:33

标签: sql vb.net

我想使用formatsqlparam更新我的数据库,但是当我调试它时,它有一个错误说:

“','。'附近的语法不正确。”

这是我的代码:

    Dim sql2 As String = "update infoHotel set nameHotel = N" & FormatSqlParam(hotel) & _
                                                       ", knownAs1 = N" & FormatSqlParam(KnownAs(0)) & _
                                                       ", knownAs2 = N" & FormatSqlParam(KnownAs(1)) & _
                                                       ", knownAs3 = N" & FormatSqlParam(KnownAs(2)) & _
                                                       ", knownAs4 = N" & FormatSqlParam(KnownAs(3)) & _
                                                       ", streetAddress = N" & FormatSqlParam(StreetAddress) & _
                                                       ", locality = N" & FormatSqlParam(Locality) & _
                                                       ", postalCode = N" & FormatSqlParam(PostalCode) & _
                                                       ", country = N" & FormatSqlParam(Country) & _
                                                       ", addressFull = N" & FormatSqlParam(address) & _
                                                       ", tel = N" & FormatSqlParam(contact) & ","

    Dim objCommand3 As New SqlCommand(sql2, conn)
    objCommand3.ExecuteNonQuery()

也许我错过了一些语法,但我找不到它的位置。我希望有人可以提供帮助。提前致谢。我正在使用VB.Net和SQL。

2 个答案:

答案 0 :(得分:4)

最后一行应该是这样的:

", tel = N" & FormatSqlParam(contact)

此外,您的语句中没有Where子句,因此这将更新表中的所有行。

答案 1 :(得分:1)

看起来尾随的逗号就是你的问题:

“,tel = N”& FormatSqlParam(联系)& “”