PreviousData Provider for .NET Guide (9.1 revision 1) Next

Using the CommandBuilder

Show this topic in Library frames

The following code example, which uses the emp sample table (see Sample Tables for Pervasive.SQL ), uses the CommandBuilder to create a SQL statement on Pervasive.SQL:

PsqlConnection    DBConn; 
DBConn = new PsqlConnection("ServerDSN=DEMODATA; 
								UID=test; 
								PWD=test; 
								Server=localhost;"); 
PsqlDataAdapter    myDataAdapter = new 
PsqlDataAdapter(); 
PsqlCommand    DBCmd = new PsqlCommand("select * from 
emp",DBConn); 
myDataAdapter.SelectCommand = DBCmd; 
//  Set up the CommandBuilder 
PsqlCommandBuilder  CommBuild = new 
PsqlCommandBuilder(myDataAdapter); 
DataSet      myDataSet = new DataSet(); 
try  
{ 
    DBConn.Open(); 
    myDataAdapter.Fill(myDataSet); 
    //  Now change the salary of the first employee 
    DataRow     myRow; 
    myRow = myDataSet.Tables["Table"].Rows[0]; 
    myRow["sal"] = 95000; 
    // Tell the DataAdapter to resynch with the 
Pervasive.SQL server. 
    // Without the CommandBuilder, this line would fail. 
    myDataAdapter.Update(myDataSet); 
} 
catch (Exception ex)  
{ 
    // Display any exceptions in a messagebox 
    MessageBox.Show (ex.Message); 
} 
//  Close the connection 
DBConn.Close(); 

Chapter contents
Publication contents

Prev topic: Using a Local Transaction
Next topic: Retrieving a Result Set using a DataAdapter Object