473,387 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Recordsets in .NET

CR
I am making the switch to .NET from VB6. In VB6 you could access data
by using the Data Environment and Data Control. I found both to be
totally useless. I can just as easily accomplish the same task with
code. For example if I wanted to populate a textbox I would do
something like this:

Dim rst As New Recordset
Dim cnn as New Connection

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"
rst.Open "Select * From Table1", cnn
Text1.Text = rst!Field1

Using code, in my opinion, is much easier and more flexible than using
the Data Environment Wizard and the data control. Plus you can use in
in your VBA macros.

I have a tutorial on .NET but it seems to only cover .NET's version of
the Data Environment and Data control. I think they call it the Server
Explorer and Data Adapter.

Is there a way to access data using straight VB code like I did in
VB6?

Thanks!

Chuck.
Nov 20 '05 #1
11 4059
You can do the same in .NET (which I prefer over those
drag and drop wizards):

Dim cnn As OleDbConnection = New OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\test\test.mdb;")
cnn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("Select * From
Table1", cnn)
Dim rdr As OleDbDataReader = cmd.ExecuteReader()
If rdr.Read() Then
Text1.Text = rdr(0)
End If

Bin Song, MCP
-----Original Message-----
I am making the switch to .NET from VB6. In VB6 you could access databy using the Data Environment and Data Control. I found both to betotally useless. I can just as easily accomplish the same task withcode. For example if I wanted to populate a textbox I would dosomething like this:

Dim rst As New Recordset
Dim cnn as New Connection

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"
rst.Open "Select * From Table1", cnn
Text1.Text = rst!Field1

Using code, in my opinion, is much easier and more flexible than usingthe Data Environment Wizard and the data control. Plus you can use inin your VBA macros.

I have a tutorial on .NET but it seems to only cover .NET's version ofthe Data Environment and Data control. I think they call it the ServerExplorer and Data Adapter.

Is there a way to access data using straight VB code like I did inVB6?

Thanks!

Chuck.
.

Nov 20 '05 #2
Cor
Hi CR,

In addition to Bing Song a little sample, how to use it with a dataset
Just typed from your example, so watch typos.

\\\\
dim connString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"

dim SqlString as string = "Select * From Table1"
Dim conn As New OledbConnection(connString)
Dim cmd As New OleDbCommand(sqlStr, Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, "Table1")
conn.close
///

I hope this helps a little bit.

Cor
Nov 20 '05 #3
CR
"Bin Song" <an*******@discussions.microsoft.com> wrote in message news:<02****************************@phx.gbl>...
Thanks! That saves me a lot of trouble.

You can do the same in .NET (which I prefer over those
drag and drop wizards):

Dim cnn As OleDbConnection = New OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\test\test.mdb;")
cnn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("Select * From
Table1", cnn)
Dim rdr As OleDbDataReader = cmd.ExecuteReader()
If rdr.Read() Then
Text1.Text = rdr(0)
End If

Bin Song, MCP
-----Original Message-----
I am making the switch to .NET from VB6. In VB6 you could

access data
by using the Data Environment and Data Control. I found

both to be
totally useless. I can just as easily accomplish the same

task with
code. For example if I wanted to populate a textbox I

would do
something like this:

Dim rst As New Recordset
Dim cnn as New Connection

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"
rst.Open "Select * From Table1", cnn
Text1.Text = rst!Field1

Using code, in my opinion, is much easier and more

flexible than using
the Data Environment Wizard and the data control. Plus

you can use in
in your VBA macros.

I have a tutorial on .NET but it seems to only

cover .NET's version of
the Data Environment and Data control. I think they call

it the Server
Explorer and Data Adapter.

Is there a way to access data using straight VB code like

I did in
VB6?

Thanks!

Chuck.
.

Nov 20 '05 #4
CR
"Cor" <no*@non.com> wrote in message news:<#9**************@TK2MSFTNGP09.phx.gbl>...

I appreciate the help!

Chuck.

Hi CR,

In addition to Bing Song a little sample, how to use it with a dataset
Just typed from your example, so watch typos.

\\\\
dim connString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"

dim SqlString as string = "Select * From Table1"
Dim conn As New OledbConnection(connString)
Dim cmd As New OleDbCommand(sqlStr, Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, "Table1")
conn.close
///

I hope this helps a little bit.

Cor

Nov 20 '05 #5
CR
"Cor" <no*@non.com> wrote in message news:<#9**************@TK2MSFTNGP09.phx.gbl>...
Hi CR,

In addition to Bing Song a little sample, how to use it with a dataset
Just typed from your example, so watch typos.

\\\\
dim connString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"

dim SqlString as string = "Select * From Table1"
Dim conn As New OledbConnection(connString)
Dim cmd As New OleDbCommand(sqlStr, Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, "Table1")
conn.close


I figured out how to access data in the DataReader but I can't figure
out how to access the data in the DataSet. In this example if I had a
field in Table1 called Field1, how would I get to the value in Field1?
Nov 20 '05 #6
"CR" <cr***@hotmail.com> schrieb
I figured out how to access data in the DataReader but I can't
figure out how to access the data in the DataSet. In this example if
I had a field in Table1 called Field1, how would I get to the value
in Field1?


Only a question: Have you already read the documentation of the DataSet (and
other ADO.NET related topics)?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
Cor
I figured out how to access data in the DataReader but I can't figure
out how to access the data in the DataSet. In this example if I had a
field in Table1 called Field1, how would I get to the value in Field1?


For the first record(row)

ds.tables(0).rows(0).item("Field1")

"> > \\\\
dim connString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"

dim SqlString as string = "Select * From Table1"
Dim conn As New OledbConnection(connString)
Dim cmd As New OleDbCommand(sqlStr, Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, "Table1")
conn.close

Nov 20 '05 #8
CR
"Armin Zingler" <az*******@freenet.de> wrote in message news:<e2*************@TK2MSFTNGP09.phx.gbl>...
"CR" <cr***@hotmail.com> schrieb
I figured out how to access data in the DataReader but I can't
figure out how to access the data in the DataSet. In this example if
I had a field in Table1 called Field1, how would I get to the value
in Field1?


Only a question: Have you already read the documentation of the DataSet (and
other ADO.NET related topics)?


Some of the online help, but it's a little overwhelming. For example
I'm not sure if I should even be using the DataSet object, maybe I
only need the DataReader. What documentation would you recommend I
read to get a good overview of this topic?
Nov 20 '05 #9
CR
"Cor" <no*@non.com> wrote in message news:<e0**************@TK2MSFTNGP09.phx.gbl>...
I figured out how to access data in the DataReader but I can't figure
out how to access the data in the DataSet. In this example if I had a
field in Table1 called Field1, how would I get to the value in Field1?


For the first record(row)

ds.tables(0).rows(0).item("Field1")


Works! Thanks!

Chuck.
Nov 20 '05 #10
"CR" <cr***@hotmail.com> schrieb
"Armin Zingler" <az*******@freenet.de> wrote in message
news:<e2*************@TK2MSFTNGP09.phx.gbl>...
"CR" <cr***@hotmail.com> schrieb
I figured out how to access data in the DataReader but I can't
figure out how to access the data in the DataSet. In this example
if I had a field in Table1 called Field1, how would I get to the
value in Field1?


Only a question: Have you already read the documentation of the
DataSet (and other ADO.NET related topics)?


Some of the online help, but it's a little overwhelming. For
example I'm not sure if I should even be using the DataSet object,
maybe I only need the DataReader. What documentation would you
recommend I read to get a good overview of this topic?


Concerning the Dataset I recommend
http://msdn.microsoft.com/library/en...ngdatasets.asp
http://msdn.microsoft.com/library/en...riDatasets.asp

If you only want to process data from the database sequentially, you can use
a DataReader. As the name says, it is used to read the data from the
databse. A dataset is an object that locally stores the content of the
records read, and you'll be able to access the records randomly.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #11
CR
"Armin Zingler" <az*******@freenet.de> wrote in message
Some of the online help, but it's a little overwhelming. For
example I'm not sure if I should even be using the DataSet object,
maybe I only need the DataReader. What documentation would you
recommend I read to get a good overview of this topic?


Concerning the Dataset I recommend
http://msdn.microsoft.com/library/en...ngdatasets.asp
http://msdn.microsoft.com/library/en...riDatasets.asp

If you only want to process data from the database sequentially, you can use
a DataReader. As the name says, it is used to read the data from the
databse. A dataset is an object that locally stores the content of the
records read, and you'll be able to access the records randomly.


I just found a good book that also has a nice summary of the dataset
object. I hate to ask stupid questions but I'm in that awkward "just
starting" phase where you don't even know what questions to ask let
alone the answers.

Thanks!

Chuck.
Nov 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Marco Alting | last post by:
Is it possible to INNER JOIN two recordsets in ASP? I don't mean the normal JOIN you would use with two tables, but actually join the recordsets in ASP?
2
by: Steve Marciniak | last post by:
I'm trying to display different recordsets (which are 1 field each) as columns right next to one another. For example, Recordset1 is displayed on the left hand side of the screen. Recordset2 is...
6
by: Steve Jorgensen | last post by:
I keep having problems in which ADO disconnected recordset work under some circumstances, but lose all their data at other times, having no rows or fields, though the recordset object still exists....
2
by: Pieter Linden | last post by:
The answer to this one is probably "test it yourself and find out!", but I'll ask anyway. Pursuant to my previous question - sending separate recordsets to Word using the CreateTableFromRecordset...
1
by: lakshmi | last post by:
Hi all, I recently rewrote a data intensive C++ program in C#. The C++ program was traversing 3 recordsets that were all open at the same time. I replaced those 3 recordsets with 3 .NET data...
16
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
24
by: Donald Grove | last post by:
I want to populate an array with values from an ado recordset (multiple rows) I use the absolute position of the cursor in the recordset to define the row of my array to be populated. I have a...
4
by: mrmagoo | last post by:
I'm building a vb.net Forms project that is getting data from a SQL Server database. One of the main goals of the project is to be really responsive to events, such as textbox change events. I...
4
by: rdemyan via AccessMonster.com | last post by:
Can someone help me with creating code that will look for DAO recordsets in modules and then check to see if the recordset is also closed in the module. All of my recordsets are of the form rs*...
11
by: BeckR | last post by:
Hello - Thanks for reading my post. I am a newbie when it comes to VBA programming, but have managed to do what I need to do, until now. I have an Access 2000 database (running WinXP Pro...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.