Hi
I have a routine, which reads in one dataset and then writes back to an sql table. This worked fine but someone has added an account code, which has an apostrophe in it!
My sql2 statement falls over when it hits this record. Anyone know how to get around this? I presume I need to be able to add another apostrophe to my “MyDataSet.Tables(0).Rows(dsCounter).Item(0)” statement but I’m not sure how to do that!
Here’s my code:
…code to fill MyDataSet
Dim dsCounter As Integer
Dim Sql2 As String
MyDataSet2 = New DataSet
With MyDataSet.Tables(0)
For dsCounter = 0 To .Rows.Count - 1 'loop
If MyDataSet.Tables(0).Rows(dsCounter).Item(1) Is System.DBNull.Value Then
Sql2 = "UPDATE tblDRAMisc SET tblDRAMisc.Colour = 'Green' WHERE tblDRAMisc.[Account Code] = '" & MyDataSet.Tables(0).Rows(dsCounter).Item(0) & "'"
MyDataAdapter2 = New System.Data.SqlClient.SqlDataAdapter(Sql2, MyConnection)
MyDataAdapter2.Fill(MyDataSet2, "tblDRAMisc")
End If
Next
End With
Thanks
Andrew
I have a routine, which reads in one dataset and then writes back to an sql table. This worked fine but someone has added an account code, which has an apostrophe in it!
My sql2 statement falls over when it hits this record. Anyone know how to get around this? I presume I need to be able to add another apostrophe to my “MyDataSet.Tables(0).Rows(dsCounter).Item(0)” statement but I’m not sure how to do that!
Here’s my code:
…code to fill MyDataSet
Dim dsCounter As Integer
Dim Sql2 As String
MyDataSet2 = New DataSet
With MyDataSet.Tables(0)
For dsCounter = 0 To .Rows.Count - 1 'loop
If MyDataSet.Tables(0).Rows(dsCounter).Item(1) Is System.DBNull.Value Then
Sql2 = "UPDATE tblDRAMisc SET tblDRAMisc.Colour = 'Green' WHERE tblDRAMisc.[Account Code] = '" & MyDataSet.Tables(0).Rows(dsCounter).Item(0) & "'"
MyDataAdapter2 = New System.Data.SqlClient.SqlDataAdapter(Sql2, MyConnection)
MyDataAdapter2.Fill(MyDataSet2, "tblDRAMisc")
End If
Next
End With
Thanks
Andrew