SQLiteCommandBuilder Class
Automatically generates single-table commands used to reconcile changes made to a
System.Data.DataSet with the SQLite.
The following example uses
SQLiteCommand, along with
SQLiteDataAdapter and
SQLiteConnection, to select rows from SQLite. The example is passed an initialized
System.Data.DataSet, a connection string, a query string that is SQL SELECT statement, and a string that is the name of the SQLite table. The example then creates a
SQLiteCommandBuilder.
public DataSet SelectSQLiteSrvRows(DataSet myDataSet,string sqConnection,string mySelectQuery,string myTableName)
{
SQLiteConnection myConn = new SQLiteConnection(sqConnection);
SQLiteDataAdapter myDataAdapter = new SQLiteDataAdapter();
myDataAdapter.SelectCommand = new SQLiteCommand(mySelectQuery, myConn);
SQLiteCommandBuilder sqCommandBuilder = new SQLiteCommandBuilder(myDataAdapter);
myConn.Open();
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet, "Departments");
//code to modify data in dataset here
//Without the SQLiteCommandBuilder this line would fail
myDataAdapter.Update(myDataSet, "Departments");
myConn.Close();
return myDataSet;
}
Public Function SelectSQLiteSrvRows(myDataSet As DataSet, sqConnection As String, mySelectQuery As String, myTableName As String) As DataSet
Dim myConn As New SQLiteConnection(sqConnection)
Dim myDataAdapter As New SQLiteDataAdapter()
myDataAdapter.SelectCommand = New SQLiteCommand(mySelectQuery, myConn)
Dim sqCommandBuilder As SQLiteCommandBuilder = New SQLiteCommandBuilder(myDataAdapter)
myConn.Open()
Dim myDataSet As DataSet = New DataSet
myDataAdapter.Fill(myDataSet, "Departments")
' Code to modify data in DataSet here
' Without the SQLiteCommandBuilder this line would fail.
myDataAdapter.Update(myDataSet, "Departments")
myConn.Close()
SelectSQLiteSrvRows = myDataSet
End Function