Simple ADO.Net Recordset.

G

Guest

My background is in MS Access and I am in the process of migrating my
skillsets to Visual Basic.Net. So far I am able to display data in
DataGridViews and Combo Box, etc with not problem. What I'm not so sure about
is bullding a recordset so that I can iterate through the record set and
perform tasks. I guess this would be a dataset or a table adapter. How would
I basically achieve a code module that does the same as the code below?

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "stored procedure/table", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic
Do Until rst.EOF
rst.AddNew
' Add, edit, delete or just read data here.
rst.Update
rst.Delete
rst.MoveNext
Loop

This is how I step through records from Access using SQL Server. How would I
achieve basically the same thing in Visual Basic.Net? Or, can someone provide
a simple snapshot of the equivilant for VB.Net?

Thank you.
 
D

Dieter Inscheidt

I guess that letting VB convert your VB6 project automatically is the
smartest thing you could do.
Select "open" in the file menu, then choose your existing VB6 project
that contains the code you want to have converted.
Cheers,
Dieter
 
R

Ralph

Greg said:
My background is in MS Access and I am in the process of migrating my
skillsets to Visual Basic.Net. So far I am able to display data in
DataGridViews and Combo Box, etc with not problem. What I'm not so sure about
is bullding a recordset so that I can iterate through the record set and
perform tasks. I guess this would be a dataset or a table adapter. How would
I basically achieve a code module that does the same as the code below?

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "stored procedure/table", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic
Do Until rst.EOF
rst.AddNew
' Add, edit, delete or just read data here.
rst.Update
rst.Delete
rst.MoveNext
Loop

This is how I step through records from Access using SQL Server. How would I
achieve basically the same thing in Visual Basic.Net? Or, can someone provide
a simple snapshot of the equivilant for VB.Net?

Thank you.

There's a couple of zillion out there.
Are you using VB 2005 Express or Std/Pro? Or something else?
When you start up the IDE ...
"Getting Started" box select "How Do I ...?" and select Data Access.

Here is a quick snapshot:
http://asp.dotnetheaven.com/howto/doc/adoplus/employees.aspx

Standard Warning! ADO.Net looks like ADO, but it ain't. Don't make
assumptions. Treat it like a new ballgame. <g>

hth
-ralph
 
J

josephshamiltons

There's a couple of zillion out there.
Are you using VB 2005 Express or Std/Pro? Or something else?
When you start up the IDE ...
"Getting Started" box select "How Do I ...?" and select Data Access.

Here is a quick snapshot:http://asp.dotnetheaven.com/howto/doc/adoplus/employees.aspx

Standard Warning! ADO.Net looks like ADO, but it ain't. Don't make
assumptions. Treat it like a new ballgame. <g>

hth
-ralph

Dim rst As ADODB.Recordset
Dim conn as new SqlConnection(connectionString)
Dim comm as new SqlCommand(query,conn)
Dim reader as SqlDataReader= comm.ExecuteReader()

dim variable as string

while reader.read
variable = reader("ColumnName")

end while



'use this for an query that is not a select

comm.CommandText = "Update table set values('" + value +"'"
comm.ExecuteNonQuery

The reader allows you forward only access to a recordset.

Use a datatable or dataset for a disconnected very intuitive model of
a database or a databasetable.
 
L

Linda Liu [MSFT]

Hi Greg,

Joseph has given the equivilant code snipet for ADO.NET.

In ADO you scan sequentially through the rows of the recordset using the
ADO MoveNext method. In ADO.NET, rows are represented as collections, so
you can loop through a table as you would through any collection, or access
particular rows via ordinal or primary key index.

Alternatively, you can use the ADO.NET DataReader to retrieve a read-only,
forward-only stream of data from a database. Results are returned as the
query executes, and are stored in the network buffer on the client until
you request them using the Read method of the DataReader.

Using the DataReader can increase application performance both by
retrieving data as soon as it is available, rather than waiting for the
entire results of the query to be returned, and (by default) storing only
one row at a time in memory, reducing system overhead. Of course, in this
case, if you want to save changes back to the database, you need to use
SqlCommand object to do it.

For more information on ADO.NET, you may refer to the following MSDN
documents:

'Comparison of ADO.NET and ADO'
http://msdn2.microsoft.com/en-us/library/904fck4k(vs.71).aspx

'Introduction to Data Access with ADO.NET'
http://msdn2.microsoft.com/en-us/library/0wxwcakt(vs.71).aspx

'Retrieving Data Using the DataReader'
http://msdn2.microsoft.com/en-us/library/aa720705(VS.71).aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

Linda Liu [MSFT]

Hi Greg,

I'm reviewing this post and would like to know the status of this issue.

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top