I want to insert data from DatagridView1
to my Access (mdb) database on my Visual Basic Project. I have a large amount of data (approximately 12,000 lines) on Datagridview1
. So I use a For
loop to insert.
Here is my code:
for i = 0 to Datagridview1.Rows.Count - 1
a = Datagridview1.Rows(i).Cells(0).Value
b = Datagridview1.Rows(i).Cells(1).Value
c = Datagridview1.Rows(i).Cells(2).Value
d = Datagridview1.Rows(i).Cells(3).Value
If studentsTableAdapter.CountStudent(a, b)=0 Then
studentsTableAdapter.Insert(a, b, "-", "New", c, 1)
End If
infoTxt.Text = "Saving " & i & "/" & Total
infoTxt.Refresh()
Next i
It works as expected, but sometimes it stops to insert and an error occurs like:
System.Data.OleDb.OleDbException (0x80004005): Unrecognized database format
This error occurs on different steps of for loops. (some times it does not occur).
Is there any reliable way to insert large amount of data from Datagridview1
to mdb database?
User contributions licensed under CC BY-SA 3.0