i got sql syntax error when i debug my application
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) & ","
精彩评论