Created a vb.net app that is moving data from Microsoft SQL Server to MySQL. All my insert functions have worked so far except the following. It appears that the issue is with a field that has comma’s in the text and is causing a problem.
I believe the issue is with the column ‘Categories’. It has values like ’11|0,1|0,12|0′.
Are comma needed to be handled in a special way?
Error:
Sql error: MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Separator,C_ID,EntryDt,S_ID) VALUES (1,1455090, ’11|0,1’ at line 1
Code:
#Region " InsertTable_Activity "
Function InsertTable_Activity(ByVal Activity_ID As Integer, _
ByVal Categories As String, _
ByVal Separator As String, _
ByVal C_ID As Integer, _
ByVal EntryDt As DateTime, _
ByVal S_ID As Integer, _
ByVal myCon As MySqlConnection) As String
Dim sRetVal As String = ""
Dim sSQL As String = "INSERT INTO CandidateInsertResumeDetailCategories_Activity (Activity_ID,Categories,Separator,C_ID,EntryDt,S_ID) VALUES (?Activity_ID, ?Categories, ?Separator, ?C_ID,?EntryDt,?S_ID)"
Dim myCmd As MySqlCommand = New MySqlCommand(sSQL, myCon)
myCmd.CommandType = Data.CommandType.Text
myCmd.Parameters.Add(New MySqlParameter("?Activity_ID", MySqlDbType.Int32)).Value = Activity_ID
myCmd.Parameters.Add(New MySqlParameter("?Categories", MySqlDbType.VarChar, 500)).Value = Categories
myCmd.Parameters.Add(New MySqlParameter("?Separator", MySqlDbType.VarChar, 10)).Value = Separator
myCmd.Parameters.Add(New MySqlParameter("?C_ID", MySqlDbType.Int32)).Value = C_ID
myCmd.Parameters.Add(New MySqlParameter("?EntryDt", MySqlDbType.DateTime)).Value = EntryDt
myCmd.Parameters.Add(New MySqlParameter("?S_ID", MySqlDbType.Int32)).Value = S_ID
Try
If myCon.State <> Data.ConnectionState.Open Then
myCon.Open()
End If
myCmd.ExecuteNonQuery()
myCmd.Dispose()
Catch sqlEx As MySqlException
sRetVal = "ERROR: Sql error: " & sqlEx.ToString & vbCrLf & " - SQL used: " & sSQL
Catch ex As Exception
sRetVal = "ERROR: Regular error: " & ex.ToString & vbCrLf & " - SQL used: " & sSQL
Finally
End Try
Return sRetVal
End Function
#End Region
SEPARATORis a reserved keyword, you should escape it with backtick,Another word-of-advice is not to use any names which on the list of reserved keywords.