dr223
May 12th, 2010, 05:08 AM
Hi,
I am trying to insert data to my sql database from a datagrid, and have the following error as highlighted, how can I change the code to be able to insert the data to the table
Private Sub Exportdata()
Dim cmd As New SqlCommand
Dim conn As SqlConnection = GetDbConnection()
Dim query As String
Dim irow As Integer
For irow = 0 To DataGrid1.Item - 1
Try
query = "INSERT INTO dbo.tbltest (Pat_eid, event_date) VALUES (" & _
DataGrid1.Item(irow).Cells(0).Value & ", '" & _
DataGrid1.Item(irow).Cells(1).Value & ")"
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "VeriSIS")
End Try
Next irow
End Sub
Thanks
I am trying to insert data to my sql database from a datagrid, and have the following error as highlighted, how can I change the code to be able to insert the data to the table
Private Sub Exportdata()
Dim cmd As New SqlCommand
Dim conn As SqlConnection = GetDbConnection()
Dim query As String
Dim irow As Integer
For irow = 0 To DataGrid1.Item - 1
Try
query = "INSERT INTO dbo.tbltest (Pat_eid, event_date) VALUES (" & _
DataGrid1.Item(irow).Cells(0).Value & ", '" & _
DataGrid1.Item(irow).Cells(1).Value & ")"
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "VeriSIS")
End Try
Next irow
End Sub
Thanks