アポストロフィを処理するSQLCommandクエリの更新に関する問題が発生しています。私はアポストロフィやその他のアクセント文字を持つ編集されたテキストを受け入れるグリッドビューを持っています。アポストロフィでSQL UPDATEが失敗する
UPDATEは、入力されたテキストのアポストロフィにエラーをスローし続け、SQL UPDATEが失敗する原因となります。
ここではコードです:
Dim lbl1 As Label = GridView3.Rows(e.RowIndex).Cells(0).FindControl("Label1")
IDVal = lbl1.Text
' New translation
Dim TB1 As TextBox = GridView3.Rows(e.RowIndex).Cells(0).FindControl("TextBox1")
updateString = TB1.Text
updateString = HttpUtility.HtmlAttributeEncode(updateString)
' Brief Description
Dim TB2 As TextBox = GridView3.Rows(e.RowIndex).Cells(0).FindControl("TextBox2")
newBrief = TB2.Text
If newBrief = "" Then
newBrief = DBNull.Value.ToString
Else
newBrief = TB2.Text
End If
' update the corresponding string value for Record
rootTableUpdate = "UPDATE " + userTable + " SET lang_String = '" + updateString + "', date_Changed ='" + myDate + "', prev_LangString = '" + Session("oldString") + "', brief_Descrip = '" + newBrief + "', needsTranslation = 'False', submittedBy= '" + userName + "' WHERE [Id] = " + IDVal + ";"
Dim command1 As New SqlCommand(rootTableUpdate, connection)
connection.Open()
command1.ExecuteNonQuery()
connection.Close()
以下error'd単語が実際にある:d'alimentation.
Incorrect syntax near 'alimentation'.
Unclosed quotation mark after the character string ' WHERE [Id] = 258;'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
例外の詳細:
System.Data.SqlClient.SqlException: Incorrect syntax near 'alimentation'.
Unclosed quotation mark after the character string ' WHERE [Id] = 258;'.
ソースエラー:
は、Line 164: Dim command1 As New SqlCommand(rootTableUpdate, connection)
Line 165: connection.Open()
Line 166: command1.ExecuteNonQuery()
SQEE、VB.net
ありがとう、いくつかの値がNULLの場合はどうなりますか? – htm11h
その後、DBNull.Valueをパラメータ値として渡してください – Curt
ありがとうございます!今働いている。 – htm11h