Update sqlite file from datatable
The SQLiteDataAdapter
class is the simplest choice for this kind of updates. The method Update of the class scans the DataTable passed and for each row that has the RowState property different from DataRowState.Unchanged executes the appropriate INSERT, DELETE, UPDATE command (if the SELECT command extracts from the DataTable the primary key). So assuming that your SELECT * FROM Data
returns also the primary key of the table you could change your code to take advantage of the SQLiteDataAdapter functionality
Imports System.Data.SQLitePublic Class DBOps ' Global because you create it in the ImportGEDb3 and use it in the SaveGEDB3 ' Private daImport As SQLiteDataAdapter Public Function ImportGEDb3(Filepath As String) As DataTable Dim dt As New DataTable("Data") daImport = new SQLiteDataAdapter("Select * from Data", "Data Source='" & Filepath & "'") daImport.Fill(dt) ' This is critical, it is the SQLiteCommandBuilder that takes ' ' the SQLiteDataAdapter SELECT statement and builds the required' ' INSERT,UPDATE,DELETE commands.' Dim builder = new SQLiteCommandBuilder(daImport) Return dt End Function Public Sub SaveGEDb3(dt as datatable) if daImport IsNot Nothing Then daImport.Update(dt) End If End Sub End class