Discussion Locked

how do i use rs!field in vb.net

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

is there anyway i can use rs!field (ex: rs!customer_id) in vb.net.

when i code it in VB.net

dim str as string
set rs = new adodb.recordset
dim x as single
str = "select customer_id from person"
rs.open str, dbconn, 3,2

x = rs!customer_id ''' this is error it says to many arguments..

how do i solve it in vb.net because this the fastest way to update and manipulate records in the data using VB6 using ADO. is there i can access the records using rs? pls help

7 replies

by ashenvi

u can try writing rs.fields(0) but instead of going with ADO u try DATASETS AND DATA ADAPTERS its more faster and easy to use also. u can manipulate with records using command objects and data reader also

by gnimgnuk

The recordset is gone in ADO.NET...it has been replaced by the DataReader and the DataSet.

The DataReader is a read-only, forward-only view of data and is faster than a dataset. The DataSet has both read & write access to data. There is much documentation on ADO.NET that I think anyone wanting to migrate to .NET needs to familiarize themselves with.

Example:

Dim strConn as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Northwind.mdb"
Dim conn as OLEDBConnection = New OLEDBConnection(strConn)
Dim strSQL as String = "SELECT * FROM Customers"
conn.Open()
Dim cmd as OLEDBCommand = New OLEDBCommand(strSQL, conn)
Dim rdr as OLEDBDataReader = cmd.ExecuteReader()
While rdr.Read()
Console.Write(rdr("CustomerID").ToString() + ", ")
Console.Write(rdr("ContactName").ToString() + ", ")
Console.Write(rdr("ContactTitle").ToString() + ", ")
End While
conn.Close()
conn.Dispose()

-This is a simple example with no error trapping, which should be added.

by gnimgnuk

The recordset is gone in ADO.NET...It has been replaced by the DataReader and the DataSet.
The DataReader is a read-only, forward-only view of data. The DataSet provides a read and write access to data.
If you are migrating to ADO.NET, I highly recommend that you familiarize yourself with the new object model, because it is completely new and not really based on the old ADO model.

simple example:

Dim strConn as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Northwind.mdb"
Dim conn as OleDbConnection = New OleDbConnection(strConn)
Dim strSQL as String = "SELECT * FROM Customers"
conn.Open()
Dim cmd as OleDbCommand = New OleDbCommand(strSQL, conn)
Dim rdr as OleDbDataReader = cmd.ExecuteReader()
While rdr.Read()
Console.Write(rdr("CustomerID").ToString + ", ")
Console.Write(rdr("CustomerName").ToString + ", ")
Console.Write(rdr("CustomerTitle").ToString + "; ")
End While
conn.Close()
conn.Dispose()

by ingphoenix

It's so late for post, but other people can to have the same problem, especially for the vb6 developers that upgrade to .net

I was trying and i can to solve using:
'''
x=rs.Fields()!customer_id.Value
'''
following the past example.

I hope that will be useful

INGPHOENIX
Colombia

This discussion is closed to new replies.