objDataAdapter.SelectCommand.CommandText

cBarry263

Active member
Joined
Oct 29, 2005
Messages
42
Location
Maryland
Programming Experience
Beginner
I have opened a connection to a database, and want to run a query to it. I have used:

objDataAdapter.SelectCommand.CommandText = "query"
Dim objDataSet As DataSet = New DataSet
objDataAdapter.Fill(objDataSet, "result")

When I run the query, where does the result get stored, and how would I get access to the results returned?
 
It is stored in objDataSet.... specifically, in the DataTable called "result" in objDataSet.

objDataSet.Tables("result")

-tg
 
Okay so if it's in objDataSet.Tables("result"), how do you extract a piece of data from that table, like the value of a certain column. By that I mean, do you have to assign objDataSet.Tables("result") to some variable of a certain type?
 
You *can* but you don't have to.

Actualy this is where ADO.NET gets cool.
Previously in ADO, you first had to find the row you want (.MoveNext .Find, etc) big pain. Now, though, because everythign is disconnected, you can go right there.

objDataSet.Tables("result").Rows(0).Item(0)
That returns the first column of the first row in the datatable.
You can quickly see how easy this becomes.
You can also do a
Dim dr As DataRow
For Each dr In objDataSet.Tables("results").Rows
to loop through each row in the table.

-tg
 
Back
Top