Retrieving records using DataSet

Records can be retrieved as a DataSet by invoking the ExecuteDataSet method of the Database; also LoadDataSet can be used to load the data to an existing DataSet.

The following code block shows record retrieval using ExecuteDataSet:

//Step 1: Create Default Database instance
Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>();
//Step 2: Create Database Command - SQL String
DbCommand dbCommand = db.GetSqlStringCommand("SELECT CustomerID, FirstName, LastName FROM Customers");
//Step 3: Execute Query
DataSet categoryDataSet = db.ExecuteDataSet(dbCommand);

The given code block demonstrates retrieving a DataSet from the Customers table using a simple SQL query and executing against the configured database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.188.138