I am currently self learning (2 weeks) vb with visual studio 2015 express, Importing selected data from an access database to a datagridview, I would then like this to be written to a SQLite database.
I have the below code working but I am not sure the transaction is set up correctly as if I use the transaction or not the writing to the SQLite.db seems slow and could be quicker, do I have the transaction set up correctly ?
Dim con As String = "Data Source=C:\clients.db;Version=3;"
Dim sqConnection As New SQLiteConnection(con)
Dim sqCommand As New SQLiteCommand()
sqCommand.Connection = sqConnection
Dim myTrans As SQLiteTransaction '= sqConnection.BeginTransaction()
sqConnection.Open()
' Start a local transaction
myTrans = sqConnection.BeginTransaction()
' Assign transaction object for a pending local transaction
sqCommand.Transaction = myTrans
Try
sqCommand.CommandText = "INSERT INTO Clients (Registered, Name, Number, Details) VALUES (@Registered, @Name, @Number, @Details)"
sqCommand.Parameters.AddWithValue("@Registered", row.Cells(1).Value)
sqCommand.Parameters.AddWithValue("@Name", row.Cells(2).Value)
sqCommand.Parameters.AddWithValue("@Number", row.Cells(3).Value)
sqCommand.Parameters.AddWithValue("@Details", row.Cells(4).Value)
sqCommand.ExecuteNonQuery()
myTrans.Commit()
Application.DoEvents()
Finally
sqConnection.Close()
End Try
I have looked at various questions/replies on here which have left me even more confused. I am getting nowhere fast and seem to be going in circles. Any help much appreciated.
Aucun commentaire:
Enregistrer un commentaire