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

Limiting the Rows Returned by a Select Statement

Show this topic in Library frames

The following code example, which requires the emp table (see Sample Tables for Pervasive.SQL ), shows how to use a Command object to limit the number of rows returned by the Pervasive.SQL server:

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; 
DataSet   myDataSet = new DataSet(); 
try  
{ 
    DBConn.Open(); 
    // Set the RowSetSize on the Command object to limit 
the number  
    // of rows returned 
    DBCmd.RowSetSize = 10; 
    myDataAdapter.SelectCommand = DBCmd; 
    myDataAdapter.Fill(myDataSet); 
    // Normally, emp contains 14 rows. 
    // But with RowSetSize set to 10, the Command object 
    // will limit the result set to 10 rows. 
    
MessageBox.Show(Convert.ToString(myDataSet.Tables["
Table"].Rows.Count)); 
} 
catch (Exception ex)  
{ 
    // Display any exceptions in a messagebox 
    MessageBox.Show (ex.Message); 
} 
// Close the connection 
DBConn.Close(); 

Chapter contents
Publication contents

Prev topic: Retrieving a Result Set using a DataAdapter Object
Next topic: Updating Data in a Rowset