473,842 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataReader VS DataSet

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_Loa d(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
Dim dbConnection As New OleDbConnection (dbConnString)
Dim myDataSet As New DataSet()
Dim myDataAdapter As OleDbDataAdapte r
Dim strSql As String
Dim myDataRow As DataRow

Me.Cursor = Cursors.WaitCur sor
strSql = "SELECT Projects.Projec t_ID, Customers.Compa ny,
Customers.Feede r, Customers.Addre ss1, Customers.City, Customers.State ,
Projects.Status FROM Projects INNER JOIN Customers ON
Projects.Compan y_ID = Customers.Custo mer_ID ORDER BY Project_ID"

Try
dbConnection.Op en()
myDataAdapter = New OleDbDataAdapte r(strSql, dbConnection)
myDataAdapter.F ill(myDataSet, "DataRead")
dbConnection.Cl ose()

For Each myDataRow In myDataSet.Table s("DataRead").R ows
Dim strDataRow As String() = {myDataRow(0),
myDataRow(1), myDataRow(2), myDataRow(3), myDataRow(4), myDataRow(5),
myDataRow(6)}
ListView.Items. Add(New ListViewItem(st rDataRow))
Next
Catch
DisplayErrorMes sage("frmProjec ts: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!
Nov 20 '05 #1
1 1669
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" <iv*****@optonl ine.net> wrote in message
news:uy******** ******@TK2MSFTN GP12.phx.gbl...
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_Loa d(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
Dim dbConnection As New OleDbConnection (dbConnString)
Dim myDataSet As New DataSet()
Dim myDataAdapter As OleDbDataAdapte r
Dim strSql As String
Dim myDataRow As DataRow

Me.Cursor = Cursors.WaitCur sor
strSql = "SELECT Projects.Projec t_ID, Customers.Compa ny,
Customers.Feede r, Customers.Addre ss1, Customers.City, Customers.State ,
Projects.Status FROM Projects INNER JOIN Customers ON
Projects.Compan y_ID = Customers.Custo mer_ID ORDER BY Project_ID"

Try
dbConnection.Op en()
myDataAdapter = New OleDbDataAdapte r(strSql, dbConnection)
myDataAdapter.F ill(myDataSet, "DataRead")
dbConnection.Cl ose()

For Each myDataRow In myDataSet.Table s("DataRead").R ows
Dim strDataRow As String() = {myDataRow(0),
myDataRow(1), myDataRow(2), myDataRow(3), myDataRow(4), myDataRow(5),
myDataRow(6)}
ListView.Items. Add(New ListViewItem(st rDataRow))
Next
Catch
DisplayErrorMes sage("frmProjec ts: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!

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
363
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader in ADO.NET in MSDN and there is a confusion regarding the buffering of data in case of DATAREADER. The link for MSDN JAN 2004 is -
1
3134
by: Rob via .NET 247 | last post by:
Ok, I'm new to .NET so I'm afraid I'm doing something stupidhere, but I'm trying to populate a DataSet manually from aDataReader, and its turning out to be ridiculously difficult. Yes, I could use a DataAdapter to more easily load the DataSet,but that would entail loading a couple of gigs worth of datainto memory at once, which is bound to be bad. So I'm trying touse a DataReader to collect a group of rows, one row at a time,until I have a...
5
5769
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
14
2247
by: Bihn | last post by:
I was reading about datareader which is said to be slimmer & faster then dataset. Since the datareader have to go fetching the dat from the database every time it need it, the data it gets then should be up to date. However, both the IbuySpy and Duwamish samples and most, if not all, the shopping cart sample codes I've seen use dataset to implement the opration for ecommerce sites. So is the trip that the datareader need to go fetch the...
2
1733
by: Patreek | last post by:
Hi, I'm writing my first real asp.net app at my job, and I'd like opinions please. In my classic ASP apps that I've written, I'd often have separate files for retreiving data and returning the data to other pages that would call it. I'd return the data as arrays so that I wouldn't have to have my DB connections open all the time while the pages ran. Now in .net, it seems like I have to choose between using a SQldatareader or a...
2
3838
by: SQL | last post by:
Hi, is there a method to move to the next record in a datareader? Kind of like the rs.MoveNext from VB6... Thanks
3
1425
by: jason | last post by:
Hi, {asp .net 1.1, sp 2) I am facing problems with multi users accessing the same page. There is a datagrid in the webform. The "datareader already opened error/ object reference not found" errors will occur randomly when multi users are clicking page number (paging), any page number. The connection object is declared private and connection is closed
7
3811
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I have read some articles state that DataSet should NOT be used for large resultset. What does "large" mean? Is "large" based on # of rows/columns and/or memory required to hold the original and the changed? I'm using VS2005 with .net 3.0.
4
1282
by: Chris | last post by:
Hi, i use this to recover data via a stored procedure from a database. Imports System.Data Imports System.Data.SqlClient Public Class chat Public Shared Function myfunction() As DataSet Dim dsdata As DataSet = New DataSet() .....
0
9875
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10674
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7859
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5886
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4500
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4090
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.