473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Read and write database

When using VB6 and ADO, if I only do a Read, I will open a recordset with
Forward Only cursor and Read Only lock, thus it will be faster than a non
Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to use
OLEDBDataReader (SQLDataReader for SQL Server), when when doing a Read/Write
I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like in the following
codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)
Nov 28 '06 #1
9 1714
If you're only reading data, the DataReader is the fastest way.
I think you have to be sure to close it when you're done.

Robin S.
---------------------------
"fniles" <fn****@pfmail.comwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
When using VB6 and ADO, if I only do a Read, I will open a recordset with
Forward Only cursor and Read Only lock, thus it will be faster than a non
Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to use
OLEDBDataReader (SQLDataReader for SQL Server), when when doing a
Read/Write I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like in
the following codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)


Nov 28 '06 #2
I'd say data reader directly is faster, reason being the overhead
required to setup and populate the plumbing of the data adapter.
Though I don't think the benefit is very significant.

On Tue, 28 Nov 2006 09:36:34 -0600, "fniles" <fn****@pfmail.com>
wrote:
>When using VB6 and ADO, if I only do a Read, I will open a recordset with
Forward Only cursor and Read Only lock, thus it will be faster than a non
Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to use
OLEDBDataReader (SQLDataReader for SQL Server), when when doing a Read/Write
I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like in the following
codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)
--

Bits.Bytes.
http://bytes.thinkersroom.com
Nov 28 '06 #3
fniles,

A data adapter is never required in order to wrtie to the database.

You can use a command object to execute Update, Insert and Delete statements.

Kerry Moorman
"fniles" wrote:
When using VB6 and ADO, if I only do a Read, I will open a recordset with
Forward Only cursor and Read Only lock, thus it will be faster than a non
Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to use
OLEDBDataReader (SQLDataReader for SQL Server), when when doing a Read/Write
I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like in the following
codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)
Nov 28 '06 #4
DataAdapters use DataReaders behind the scenes to do their Select queries,
but the extra effor to set one up makes just using a DataReader via a
Command object's .ExecuteReader method much easier.
"fniles" <fn****@pfmail.comwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
When using VB6 and ADO, if I only do a Read, I will open a recordset with
Forward Only cursor and Read Only lock, thus it will be faster than a non
Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to use
OLEDBDataReader (SQLDataReader for SQL Server), when when doing a
Read/Write I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like in
the following codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)


Nov 28 '06 #5
Thank you all.
Could you please give me an example on how to use the DataReader via a
Command object's ?

Thank you very much.

"Scott M." <s-***@nospam.nospamwrote in message
news:eu**************@TK2MSFTNGP03.phx.gbl...
DataAdapters use DataReaders behind the scenes to do their Select queries,
but the extra effor to set one up makes just using a DataReader via a
Command object's .ExecuteReader method much easier.
"fniles" <fn****@pfmail.comwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
>When using VB6 and ADO, if I only do a Read, I will open a recordset with
Forward Only cursor and Read Only lock, thus it will be faster than a
non Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to use
OLEDBDataReader (SQLDataReader for SQL Server), when when doing a
Read/Write I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like in
the following codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)



Nov 28 '06 #6
Fniles

In Addition to Scott, it makes of course only sense to use the datareader if
you are not using datasets or datatables.

It can be used with the so called OO dataclasses to make your own
implementation of datahandling.

Cor

"Scott M." <s-***@nospam.nospamschreef in bericht
news:eu**************@TK2MSFTNGP03.phx.gbl...
DataAdapters use DataReaders behind the scenes to do their Select queries,
but the extra effor to set one up makes just using a DataReader via a
Command object's .ExecuteReader method much easier.
"fniles" <fn****@pfmail.comwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
>When using VB6 and ADO, if I only do a Read, I will open a recordset with
Forward Only cursor and Read Only lock, thus it will be faster than a
non Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to use
OLEDBDataReader (SQLDataReader for SQL Server), when when doing a
Read/Write I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like in
the following codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)



Nov 29 '06 #7
Be aware that this is terrible slow.

http://www.vb-tips.com/dbpages.aspx?...6-fc0d5c470f53

I hope this gives an idea,

Cor

"fniles" <fn****@pfmail.comschreef in bericht
news:OO**************@TK2MSFTNGP06.phx.gbl...
Thank you all.
Could you please give me an example on how to use the DataReader via a
Command object's ?

Thank you very much.

"Scott M." <s-***@nospam.nospamwrote in message
news:eu**************@TK2MSFTNGP03.phx.gbl...
>DataAdapters use DataReaders behind the scenes to do their Select
queries, but the extra effor to set one up makes just using a DataReader
via a Command object's .ExecuteReader method much easier.
"fniles" <fn****@pfmail.comwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
>>When using VB6 and ADO, if I only do a Read, I will open a recordset
with Forward Only cursor and Read Only lock, thus it will be faster
than a non Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to use
OLEDBDataReader (SQLDataReader for SQL Server), when when doing a
Read/Write I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like
in the following codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)




Nov 29 '06 #8
Dim conStr As String = your connection string here
Dim selectSQL As String = your select SQL statement here
Dim con As New OleDBConnection(conStr)
Dim cmd As New OleDbCommand(selectSQL, con)

Try
con.Open()
Dim dr As OleDbDataReader =
cmdExecuteReader(CommandBehavior.CloseConnection)
Do While dr.Read()
'extract your data items here, ie. x =
dr.Item("userName").ToString()
Loop
dr.Close()
Catch

Finally
'Don't really need to do this because closing the reader closes the
connection
'but a good idea that doesn't hurt
con.Close()
End Try
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:Ok**************@TK2MSFTNGP03.phx.gbl...
Be aware that this is terrible slow.

http://www.vb-tips.com/dbpages.aspx?...6-fc0d5c470f53

I hope this gives an idea,

Cor

"fniles" <fn****@pfmail.comschreef in bericht
news:OO**************@TK2MSFTNGP06.phx.gbl...
>Thank you all.
Could you please give me an example on how to use the DataReader via a
Command object's ?

Thank you very much.

"Scott M." <s-***@nospam.nospamwrote in message
news:eu**************@TK2MSFTNGP03.phx.gbl...
>>DataAdapters use DataReaders behind the scenes to do their Select
queries, but the extra effor to set one up makes just using a DataReader
via a Command object's .ExecuteReader method much easier.
"fniles" <fn****@pfmail.comwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
When using VB6 and ADO, if I only do a Read, I will open a recordset
with Forward Only cursor and Read Only lock, thus it will be faster
than a non Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to
use OLEDBDataReader (SQLDataReader for SQL Server), when when doing a
Read/Write I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like
in the following codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)




Nov 29 '06 #9
Are the following the correct codes to do use a DataReader via a Command
object's .ExecuteReader method ?

Dim OleDbCommand2 As New Data.SqlClient.SqlCommand
Dim OleDbConnection1 As New Data.SqlClient.SqlConnection
Dim dreader As Data.SqlClient.SqlDataReader
With OleDbConnection1
.ConnectionString = "Data Source=" & sDataSource & ";Initial
Catalog=pubs;User ID=" & sID & ";Password=" & sPassword
.Open()
End With
OleDbCommand2.CommandText = "update authors set au_fname = 'ffa',
au_lname='smith' where au_id = '172-32-1176'"
OleDbCommand2.Connection = OleDbConnection1
dreader = OleDbCommand2.ExecuteReader()

OR USING Stored Procedure like the following ?

Dim OleDbCommand2 As New Data.SqlClient.SqlCommand
Dim OleDbConnection1 As New Data.SqlClient.SqlConnection
Dim dreader As Data.SqlClient.SqlDataReader

With OleDbConnection1
.ConnectionString = "Data Source=" & sDataSource & ";Initial
Catalog=pubs;User ID=" & sID & ";Password=" & sPassword
.Open()
End With
OleDbCommand2.CommandText = "UpdateAuthors"
OleDbCommand2.CommandType = CommandType.StoredProcedure
OleDbCommand2.Connection = OleDbConnection1
OleDbCommand2.Parameters.Add("@lname", SqlDbType.VarChar, 40)
OleDbCommand2.Parameters.Add("@fname", SqlDbType.VarChar, 20)
OleDbCommand2.Parameters.Add("@id", SqlDbType.VarChar, 11)
OleDbCommand2.Parameters("@lname").Value = "smith"
OleDbCommand2.Parameters("@fname").Value = "ffa"
OleDbCommand2.Parameters("@id").Value = "172-32-1176"
dreader = OleDbCommand2.ExecuteReader()
dreader.Close()
OleDbConnection1.Close()

"Scott M." <s-***@nospam.nospamwrote in message
news:eu**************@TK2MSFTNGP03.phx.gbl...
DataAdapters use DataReaders behind the scenes to do their Select queries,
but the extra effor to set one up makes just using a DataReader via a
Command object's .ExecuteReader method much easier.
"fniles" <fn****@pfmail.comwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
>When using VB6 and ADO, if I only do a Read, I will open a recordset with
Forward Only cursor and Read Only lock, thus it will be faster than a
non Read recordset.
In VB.NET, when only need to do a Read, is it correct that I want to use
OLEDBDataReader (SQLDataReader for SQL Server), when when doing a
Read/Write I use OLEDBDataAdapter (SQLDataAdapter for SQL Server) like in
the following codes ?
Is using OLEDBDataReader/SQLDataReader faster than using
OLEDBDATAAdapter/SQLDataAdapter ?
Thank you
'READ ONLY
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
With cmd
.Connection = g_ConnectionDemoOLE
.CommandText = sql
dr = .ExecuteReader()
:

'READ/WRITE
Private m_da As New OleDb.OleDbDataAdapter
Private m_cmd As New OleDb.OleDbCommand
Dim m_ds As New DataSet

With m_cmd
.Connection = adoConOLE
.CommandText = sSQL
End With
m_da.SelectCommand = m_cmd
m_da.Fill(m_ds)



Nov 29 '06 #10

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

Similar topics

4
by: JDJones | last post by:
I'm trying to write a script that will read from a text list of songs that I burned onto my CD (Albums011.txt), then write to the database text the new text made ready for inserting into a...
10
by: David ROBERT | last post by:
Hello, I need to read data from a MS Access database. The program (reader) is installed on a linux box and is written in python langage. The database is MS Access 2002 installed on a Win XP box...
11
by: HolaGoogle | last post by:
hi all, can you please tell me what i should do to avoid session timeout when displaying my database info in my asp form (DisplayUserDatabase.asp)??? ** actualy it does load and display the...
7
by: Graham Taylor | last post by:
I've tried posting this in the 'microsoft.public.access' but I will post it here also, as I think it might be the webserver which is causing my problem. --------- I have an Access 2003 database...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
3
by: Doug | last post by:
Working on converting an Access front-end/SQL Server back-end to a .NET front/SQL Server back-end. We are also redesiging the SQL Server database. We have many Word/Excel documents that have...
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I try to follow Steve's paper to build a database, and store a small text file into SQL Server database and retrieve it later. Only difference between my table and Steve's table is that I use NTEXT...
4
by: farhaaad | last post by:
Hi all, i wanted to know how can i make my mdb file read only recommended, i mean when the user opens the database with holding the SHIFT key it shouldn't be read only and when opening the...
3
by: sriram347 | last post by:
Hi I am a newbie to ASP.NET. I developed a web page (project type is web application) and I keep getting this error. B]Error message : "System.AccessViolation Exception attempted to read or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.