Quick Objects Documentation Akal Tech Logo
Running a SELECT Statement and Returning a DataSet

Glossary Item Box

Database Library - Tutorial 1:

Assuming you have a Customer table (as provided in the included samples QO_SHOP database) running a simple select statement and returning a DataSet is just 2 lines of code with QuickObjects DBLibrary. The most common and redundant tasks a database application developer performs are creating a connection, creating a command and data adaptor and then filling the DataSet by executing the command, and then close the connection object etc. These mundane and redundant tasks are no longer needed when using the QuickObjects DBLibrary or the Business Logic Framework.

The following sample shows how easy it is to get a DataSet by executing a simple SELECT statement on the database.

// Create a new instance of the DatabaseObjectSQL class

// by enclosing it inside the using clause we are ensuring

// that the Dispose method gets called after the DatabaseObjectSQL instance

// is no longer needed.

using (DatabaseObjectSQL dbObj = new DatabaseObjectSQL())

{

// RunSQLReturnDataset method has multiple overloads available

// The one being used here takes a string value as the SQL command to be executed

// on the database and it returns a DataSet containing the table that was returned

// by the database from the execution of the supplied command.

DataSet ds = dbObj.RunSQLReturnDataset("SELECT * FROM CUSTOMERS");

if (ds.Tables.Count > 0)

{

this.GridView.DataSource = ds;

this.GridView.DataMember = ds.Tables[0].TableName;

}

}