Dear All Master, please help me for my first program that i want to create...i have problem for save from datagridview to access database...everytime i try to save , only first line have save...another not save...sory for my bad english language...thank's
here my code....

Sub simpen()
        Dim i As Integer
        Dim cmd As New OleDbCommand
        cmd.Connection = con
        For i = 0 To DataGridView1.Rows.Count - 1
            strsql = "insert into students_grade (student_no, student_name, grade) values (@student_no, @student_name, @grade)"
            cmd.CommandText = strsql
            With cmd.Parameters
                cmd.Parameters.AddWithValue("@student_no", DataGridView1.Rows(i).Cells(0).Value)
                cmd.Parameters.AddWithValue("@student_name", DataGridView1.Rows(i).Cells(1).Value)
                cmd.Parameters.AddWithValue("@grade", DataGridView1.Rows(i).Cells(2).Value)
            End With
            acsdr = cmd.ExecuteReader
        Next i
        MessageBox.Show("Data Inserted")
    End Sub
        Dim i As Integer
        For i = 0 To DataGridView1.Rows.Count - 1
            With DataGridView1.Rows(i)
                Dim insertCommand As New  _
                OleDb.OleDbCommand("insert into students_grade (student_no, student_name, grade) values ('" & _
                .Cells(0).Value & "','" & .Cells(1).Value & "','" & .Cells(2).Value & "')", Con)
                Catch ex As Exception
                End Try
            End With
        MessageBox.Show("Data Inserted")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.