Visual Studio 2005 Cookbook – Database, Storing the Results of a Query in Memory
Recipe 13.7. Storing the Results of a Query in Memory
Problem
While a data reader is fast and convenient, you would like to keep the retrieved data around for a while, even when you are disconnected from the database or other data source.
Solution
Use the data reader to bring the results into a data set. The DataSet object represents one or more in-memory database tables, each with its records stored in a separate DataTable object.
Discussion
The following code loads all records from the Table1 table into a DataSet object, creating a DataTable object named Table1 within that data set:
' ----- Connect to the database. Dim connectionString As String = _ “Data Source=MySystemSQLEXPRESS;” & _ “Initial Catalog=MyDatabase;Integrated Security=true” Dim theDatabase As New SqlClient.SqlConnection(connectionString) theDatabase.Open() ‘ —– Prepare the SQL statement for use by the data set. Dim sqlStatement As New SqlClient.SqlCommand( _ “SELECT * FROM Table1″, theDatabase) Read More >>
No comments yet.



