开发者

i got sql syntax error when i debug my application

开发者 https://www.devze.com 2023-01-02 19:12 出处:网络
I want to update my database using formatsqlparam, but when I debug it, it has an error saying: \"Incorrect syntax near \',\'.\"

I want to update my database using formatsqlparam, but when I debug it, it has an error saying:

"Incorrect syntax near ','."

This is my code:

    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()

Maybe I am missing some syntax, but I couldn't find where it is. I hope somebody can help. Thanks in advance. I'm using VB.Net and SQL.


The last line should be like this:

", tel = N" & FormatSqlParam(contact)

Also, you don't have a Where clause in your statement so this will update all rows in your table.


Looks like the trailing comma is your problem:

", tel = N" & FormatSqlParam(contact) & ","

0

精彩评论

暂无评论...
验证码 换一张
取 消