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)