DataReader VS DataSet

I

Ivan Weiss

Hey all, I have the following code to populate a ListView control from
my Access database. The listview is displaying a list of saved projects
that the user will be able to open, edit, or delete to work on. I know
that the DataReader is more efficient and faster than a dataset, but I
was not able to figure out how to implement it. Here is the code I have
now which works:

Private Sub frmProjects_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim dbConnection As New OleDbConnection(dbConnString)
Dim myDataSet As New DataSet()
Dim myDataAdapter As OleDbDataAdapter
Dim strSql As String
Dim myDataRow As DataRow

Me.Cursor = Cursors.WaitCursor
strSql = "SELECT Projects.Project_ID, Customers.Company,
Customers.Feeder, Customers.Address1, Customers.City, Customers.State,
Projects.Status FROM Projects INNER JOIN Customers ON
Projects.Company_ID = Customers.Customer_ID ORDER BY Project_ID"

Try
dbConnection.Open()
myDataAdapter = New OleDbDataAdapter(strSql, dbConnection)
myDataAdapter.Fill(myDataSet, "DataRead")
dbConnection.Close()

For Each myDataRow In myDataSet.Tables("DataRead").Rows
Dim strDataRow As String() = {myDataRow(0),
myDataRow(1), myDataRow(2), myDataRow(3), myDataRow(4), myDataRow(5),
myDataRow(6)}
ListView.Items.Add(New ListViewItem(strDataRow))
Next
Catch
DisplayErrorMessage("frmProjects:frmProjects_Load")
End Try

myDataSet = Nothing
myDataAdapter = Nothing

Me.Cursor = Cursors.Default
End Sub

If anyone has any ideas that would be greatly appreciated

-Ivan
 
S

Scott M.

First, a DataReader is for Read-Only, Forward-Only sets of records. If you
need to modify the data or move back & forth through the data, then the
DataReader is out. This is why the DataReader is thinner than a DataSet,
which allows multiple tables of data, relationships and constraints of data,
full movement through the data and full modification of the data.

The easiest way to generate a DataReader is to use a command object's
..ExecuteReader method which will return one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top