See Also

SQLiteCommandBuilder Members  | Devart.Data.SQLite Namespace  | SQLiteDataAdapter Class  | SQLiteConnection Class  | SQLiteCommand Class

Language

Visual Basic

C#

Show All

See AlsoLanguagesDevart.Data.SQLiteSend comments on this topic.

SQLiteCommandBuilder Class

Devart.Data.SQLite Namespace : SQLiteCommandBuilder Class

Automatically generates single-table commands used to reconcile changes made to a DataSet with the associated SQLite database.

For a list of all members of this type, see SQLiteCommandBuilder members.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Data.Common.DbCommandBuilder
            Devart.Common.DbCommandBuilderBase
               Devart.Common.DbCommandBuilder
                  Devart.Data.SQLite.SQLiteCommandBuilder

Syntax

[Visual Basic]
Public Class SQLiteCommandBuilder    Inherits DbCommandBuilder
[C#]
public class SQLiteCommandBuilder : DbCommandBuilder

Remarks

The SQLiteDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a DataSet associated with the SQLite database. However, you can create a SQLiteCommandBuilder object that generates SQL statements for single-table updates. After assigning the SQLiteDataAdapter to the SQLiteCommandBuilder, it begins to generate any additional SQL statements that you do not set.

The relationship between a SQLiteDataAdapter and its corresponding SQLiteCommandBuilder is always one-to-one. To create this correspondence, you set the DataAdapter property of the SQLiteCommandBuilder object. This causes the SQLiteCommandBuilder to register itself as a listener, which produces the output of SQLiteDataAdapter.RowUpdating events that affect the DataSet.

To generate INSERT, UPDATE, or DELETE statements, the SQLiteCommandBuilder uses the SQLiteDataAdapter.SelectCommand property to retrieve a required set of metadata. If you change the value of SQLiteDataAdapter.SelectCommand after the metadata has been retrieved (for example, after the first update), you then should call the Devart.Common.DbCommandBuilderBase.RefreshSchema method to update the metadata.

The SQLiteCommandBuilder also uses the Connection, Devart.Common.DbCommandBase.CommandTimeout, and Transaction properties referenced by the SQLiteDataAdapter.SelectCommand. The user should call Devart.Common.DbCommandBuilderBase.RefreshSchema if any of these properties are modified, or value of the SQLiteDataAdapter.SelectCommand property itself is changed. Otherwise the SQLiteDataAdapter.InsertCommand, SQLiteDataAdapter.UpdateCommand, and SQLiteDataAdapter.DeleteCommand properties retain their previous values.

If you assign null to corresponding property of SQLiteDataAdapter, the SQLiteCommandBuilder will be disassociated from the SQLiteDataAdapter, and the generated commands will no longer be used.

Example

The following example uses SQLiteCommand, along with SQLiteDataAdapter and SQLiteConnection, to select rows from a SQLite database. The example is passed an initialized 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.

[C#] 

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; 

[Visual Basic] 

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

See Also

SQLiteCommandBuilder Members  | Devart.Data.SQLite Namespace  | SQLiteDataAdapter Class  | SQLiteConnection Class  | SQLiteCommand Class

 

 


© 2008 - 2014 Devart. All Rights Reserved.