Re: Recordsets before now in .NET what?



ADO.NET (as you have discovered) does not use Recordsets to handle data. While you could use a DataReader to return the rows, you could also use a DataTable (filled with a DataReader behind the scenes). Another approach which you might try is using the Data Source wizard in VS to generate a TableAdapter.

Try
Dim cn As New OleDb.OleDbConnection(My.Settings.NwindConnectionString)
cn.Open()
Dim cmd As New OleDb.OleDbCommand("SELECT CustomerID FROM Customers", cn)
Dim dr As OleDbDataReader, myCustID As String
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows Then
dr.Read()
myCustID = CStr(dr.GetValue(0))
' or
myCustID = dr.GetString(0)
' or
myCustID = dr("CustomerID").ToString ' But this is a lot slower
' or
Dim dt As New DataTable
dt.Load(dr)
myCustID = dt.Rows(0).Item("CustomerID")
End If
cmd.Cancel()
dr.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try

This example (and a lot more) are in my new book but since you're using JET it might not be a perfect match--I discuss how to use SQL Server and migrate away from Access/JET databases.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

"Sammy" <Sammy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:CF237BA6-C806-4D1A-ADF3-884285DA5450@xxxxxxxxxxxxxxxx
USed ADO before like this

dim rs as record set
theSQl = "SELECT customerID FROM CustTabl"

I could put the value of CustID into a variable for my use
iCustI = rs.feilds("customerID")

now I'm using an oledbadaptaor to fill a dataset...

But I want only one value...the customerID..How is this done in dot net..any
examples

.



Relevant Pages

  • Re: Datareader does not work but Dataset does
    ... Dim coll As ArrayList = New ArrayList ... If Not ((dataReader = Nothing)) Then ... This is debugging code. ... If I run this code in Query Analyser ...
    (microsoft.public.dotnet.general)
  • Re: Datareader does not work but Dataset does
    ... what makes an IDataReader very lightweight. ... Private Function TestAnIDataReader(ByVal dataReader As ... Dim coll As ArrayList = New ArrayList ... This is debugging code. ...
    (microsoft.public.dotnet.general)
  • Re: Datareader does not work but Dataset does
    ... Private Function TestAnIDataReader(ByVal dataReader As IDataReader) ... Dim coll As ArrayList = New ArrayList ... This is debugging code. ...
    (microsoft.public.dotnet.general)
  • Re: How can I Import data from one text file to multiple tables?
    ... Dim rsXXX As DAO.Recordset ... Dim lngFN As Long ... 'Close recordsets and file ... >regular task, I'd do it differently, writing Access VBA code that opens ...
    (microsoft.public.access.externaldata)
  • Re: datareader questions
    ... > Dim myFinds as OleDataReader ... > ' Why does the next line of code not fill the datareader ... > myFinds = oleEmp.ExecuteReader executes the datareader should have info to ... this datasource. ...
    (microsoft.public.dotnet.languages.vb)