كود :
Private Sub Export_Data_Grid_View_To_Access_Table()
Try
Dim StudentId As Integer, FirstName, LastName, Birthday, LieuBirth, Gender, Nationalite As String
For xyz As Integer = 0 To DataGridView1.Rows.Count - 1
StudentId = Me.DataGridView1.Rows(xyz).Cells(0).Value
FirstName = Me.DataGridView1.Rows(xyz).Cells(1).Value.ToString
LastName = Me.DataGridView1.Rows(xyz).Cells(2).Value.ToString
Birthday = Me.DataGridView1.Rows(xyz).Cells(3).Value.ToString
LieuBirth = Me.DataGridView1.Rows(xyz).Cells(4).Value.ToString
Gender = Me.DataGridView1.Rows(xyz).Cells(5).Value.ToString
Nationalite = Me.DataGridView1.Rows(xyz).Cells(6).Value.ToString
Dim Sql_Str As String = "INSERT INTO TBL_STUDENT( STUDENT_Id, STUDENT_Name, STUDENT_Surname, STUDENT_Date_Naissance, STUDENT_Lieu_Naissance, STUDENT_Gender, STUDENT_Nationalite ) Values ( @STUDENT_Id, @STUDENT_Name, @STUDENT_Surname, @STUDENT_Date_Naissance, @STUDENT_Lieu_Naissance, @STUDENT_Gender, @STUDENT_Nationalite)"
Dim Cmd As New OleDb.OleDbCommand(Sql_Str, Conne)
Cmd.Parameters.AddWithValue("@STUDENT_Id", StudentId)
Cmd.Parameters.AddWithValue("@STUDENT_Name", FirstName)
Cmd.Parameters.AddWithValue("@STUDENT_Surname", LastName)
Cmd.Parameters.AddWithValue("@STUDENT_Date_Naissance", Birthday)
Cmd.Parameters.AddWithValue("@STUDENT_Lieu_Naissance", LieuBirth)
Cmd.Parameters.AddWithValue("@STUDENT_Gender", Gender)
Cmd.Parameters.AddWithValue("@STUDENT_Nationalite", Nationalite)
Cmd.ExecuteNonQuery()
Cmd.Dispose()
Next
Conne.Close()
MessageBox.Show("تمّ تصدير البيانات بنجاح", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As OleDb.OleDbException
MsgBox(ex.Message, MsgBoxStyle.Critical, "خطأ برمجي غير معيّن")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "خطأ عام غير معيّن")
End Try
End Sub