我試圖通過使用帶有SqlConnection的參數化查詢來避免在我的字符串變量中逃脫撇號,但它不工作。任何幫助,將不勝感激。防止參數查詢逃逸撇號
更新:這是當前代碼...
'Populate Connection Object
Dim oCnn As New SqlConnection(strConnection)
'Define our sql query
Dim sSQL As String = "INSERT INTO [" & foreignTable & "] (data_text) VALUES (@data_text) ; "
'Populate Command Object
Dim oCmd As New SqlCommand(sSQL, oCnn)
'Add up the parameter, associated it with its value
oCmd.Parameters.AddWithValue("@data_text", data_text)
'Opening Connection for our DB operation
oCnn.Open()
Try
Dim results As Integer = oCmd.ExecuteScalar
Catch ex As Exception
LabelImport.Text &= "<font color=red>ROOT Import ERROR: " & ex.ToString & ", From Database: " & dbName & ", Text String: " & data_text & "</font><br />"
Throw
End Try
oCnn.Close()
oCmd.Parameters.Clear()
感謝您的幫助。
IT現在可以工作,除了10條左右的記錄以外,還有apostrphes – htm11h
@ marc11h您可以定義不適用於帶撇號的10條記錄嗎?錯誤? – LarsTech
是的,給定的數量可以大得多,這是測試數據。 – htm11h