Private Sub one_btninsert_Click(sender As Object, e As EventArgs) Handles one_btninsert.Click
For i = 0 To DataGridView1.Rows.Count - 1
Dim row1 As Integer = Val(DataGridView1.Rows(i).Cells(1).Value.ToString)
Dim row2 As String = DataGridView2.Rows(i).Cells(2).Value.ToString
Dim row3 As String = DataGridView2.Rows(i).Cells(3).Value.ToString
Dim row4 As String = DataGridView2.Rows(i).Cells(4).Value.ToString
Dim row5 As String = DataGridView2.Rows(i).Cells(5).Value.ToString
Dim row6 As String = DataGridView2.Rows(i).Cells(6).Value.ToString
Dim row7 As String = DataGridView2.Rows(i).Cells(7).Value.ToString
Dim row8 As String = DataGridView2.Rows(i).Cells(8).Value.ToString
Dim row9 As String = DataGridView2.Rows(i).Cells(9).Value.ToString
Dim row10 As String = DataGridView2.Rows(i).Cells(10).Value.ToString
Dim row11 As String = DataGridView2.Rows(i).Cells(11).Value.ToString
Dim row12 As String = DataGridView2.Rows(i).Cells(12).Value.ToString
Dim row13 As String = DataGridView2.Rows(i).Cells(13).Value.ToString
Dim row14 As String = DataGridView2.Rows(i).Cells(14).Value.ToString
Dim row15 As String = DataGridView2.Rows(i).Cells(15).Value.ToString
Dim row16 As String = DataGridView2.Rows(i).Cells(16).Value.ToString
Dim row17 As String = DataGridView2.Rows(i).Cells(17).Value.ToString
Dim sqlquery As String = "INSERT INTO nursery(regno,rollno,nepali,com_english_w,com_english_o,com_math,social_w,social_o,science_w,science_o,hpe_w,hpe_o,creative,health,extra_math,extra_eng_w,extra_eng_o) values('" & row1 & "','" & row2 & "','" & row3 & "','" & row4 & "','" & row5 & "','" & row6 & "','" & row7 & "','" & row8 & "','" & row9 & "','" & row10 & "','" & row11 & "','" & row12 & "','" & row13 & "','" & row14 & "','" & row15 & "','" & row16 & "','" & row17 & "')"
Dim sqlcommand As New OleDbCommand
With sqlcommand
.CommandText = sqlquery
.Connection = conn
.ExecuteNonQuery()
End With
Next
End Sub
Private Sub DataGridView2_CellValidating(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs) Handles DataGridView2.CellValidating
If DataGridView2.Item(e.ColumnIndex, e.RowIndex).Value Is Nothing Then
' Show the user a message
MessageBox.Show("You have left the cell empty")
' Fail validation (prevent them from leaving the cell)
e.Cancel = True
End If
End Sub
hi, its code for inserting data from datagrid view to ms access. while inserting i need to valid null values in each cells. i wrote above code but it doesnot let me to move from one cells to another cells after inserting data in one cells. MessageBox.Show("You have left the cell empty").. always this message appears.. plz help..