I followed the suggestion from
http://www.daniweb.com/software-development/vbnet/threads/388317 this thread. however i face a bit of a problem
in my case i have a combobox at row(i).cells(0)
the code seems to take the last new rows where there's not record and shows error
the debug error msg is
A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll INSERT into taken(typeID,quantity) VALUES (5,39) INSERT into taken(typeID,quantity) VALUES (,)
here the typeID is listed in combo derived from database table.
my code is
Try con.Open() If DataGridView1.Rows.Count > 0 Then Dim cmd As New OleDbCommand cmd.Connection = con cmd.CommandType = Data.CommandType.Text Dim strcommandText As String = "INSERT into taken(typeID,quantity) VALUES (" Dim values As String = "" For i As Integer = 0 To DataGridView1.Rows.Count - 1 values = strcommandText & DataGridView1.Rows(i).Cells(0).Value & "," & DataGridView1.Rows(i).Cells(2).Value & ")" cmd.CommandText = values Debug.Print(cmd.CommandText) cmd.ExecuteNonQuery() Next i cmd = Nothing End If con.Close() MsgBox("Success") Catch ex As Exception MsgBox(ex.ToString) Finally End Try
i was hoping
For i As Integer = 0 To DataGridView1.Rows.Count - 1 to solve this problem but it doesn't. don't know how to fix this, please help.