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

Retrieving a Result Set using a DataAdapter Object

Show this topic in Library frames

The DataAdapter is a bridge between the ADO.NET DataSet object and the underlying DBMS. The DataAdapter can be used to fill a DataSet with a result set or multiple result sets. The following code example, which requires the emp table (see Sample Tables for Pervasive.SQL ), shows how to set up the DataAdapter to retrieve the data and fill a DataSet:

// Open connection to Pervasive.SQL database 
PsqlConnection  Conn; 
Conn = new PsqlConnection("ServerDSN=Demodata; 
		UID=test; 
		PWD=test; 
                        Server=localhost;"); 
                          
Conn.Open(); 
// Create a SQL command 
string sqlSEL = "SELECT NAME FROM emp WHERE sal>'50000'"; 
PsqlDataAdapter   myDataAdapter = new 
PsqlDataAdapter(sqlSEL, Conn); 
DataSet myDataSet = new DataSet("salDataSet"); 
try 
{ 
     myDataAdapter.Fill(myDataSet, "emp"); 
} 
catch(Exception ex)  
{ 
    // Display any exceptions in a messagebox 
    MessageBox.Show (ex.Message); 
} 
finally 
//  Close the connection 
{ 
Conn.Close(); 
} 

Chapter contents
Publication contents

Prev topic: Using the CommandBuilder
Next topic: Limiting the Rows Returned by a Select Statement