Re: Recordsets before now in .NET what?
- From: "William Vaughn" <billvaNoSPAM@xxxxxxxxx>
- Date: Fri, 3 Aug 2007 09:13:39 -0700
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
.
- Prev by Date: Re: Add Data to Independent Data Table
- Next by Date: Re: Binding to a Business Object
- Previous by thread: Re: Add Data to Independent Data Table
- Next by thread: Re: Binding to a Business Object
- Index(es):
Relevant Pages
|
|