PC Review


Reply
Thread Tools Rate Thread

DataReader VS DataSet

 
 
Ivan Weiss
Guest
Posts: n/a
 
      16th Nov 2003
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      17th Nov 2003
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.


"Ivan Weiss" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataReader vs DataSet =?Utf-8?B?UGV0ZXI=?= Microsoft VB .NET 7 3rd Aug 2007 02:48 PM
datareader vs dataset =?Utf-8?B?cm9kY2hhcg==?= Microsoft ASP .NET 4 7th Nov 2005 04:46 PM
How to use a datareader instead of a dataset? Shapper Microsoft ASP .NET 2 25th Apr 2005 03:43 PM
Datareader or Dataset ? srinivas Microsoft Dot NET 3 1st Sep 2003 10:00 AM
DataReader from DataSet Tushar Karsan Microsoft ADO .NET 11 16th Jul 2003 01:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:52 AM.