the adodc1.recordset![Datafield]

Kid_Icarus

Member
Joined
Dec 3, 2003
Messages
9
I have learned how to use datasets to populate datagrids/textboxes, and how to manipulate the data (new, save, delete). But now Im stuck. I want to do a subquery...

In VB6 I could get the data (value) in the field in the current record by:

Code:
adodc1.recordset!fieldname

But how is this done with the dataset? I could of course refer to the bound textbox, but it doesnt feel so ...professional.

Anyone?

Thanks in advance. :-\

Kid Icarus
 
Didnt follow your question because Ive actually forgotten all of VB6 data access...wow... anyway to get the field of a row:

ds.Tables(0).Rows(5)("OrderNumber")

If you were speaking of relationships then:

ds.Tables(0).Rows(5).GetParentRow("RelationshipName", RowState.Current)("UserName")

Im way off on the syntax above, but its along those lines, Im almost always use strongly typed datasets (runs faster, get intellisense, lots of other advantages), and Ive been extremely spoiled by them because I can:

ds.OrdersTables(5).CustomerRow.CustomerName

Of course none of this has the proper checking that you need to have, but its just an example, hope it helps.
 
In old school you did something like (again cant remember that far back for sure):

While rs.EOF = false
Response.Write(rs("UserName"))
rs.MoveNext
End While

In .NET you can:

For Each row as DataRow in ds.Tables(0).Rows
Debug.WriteLine(row("OrderNumber").ToString())
Next

or

For i as Integer = 0 to ds.Tables(0).Rows.Count - 1
Debug.WriteLine(DirectCast(ds.Tables(0).Rows(i)("OrderNumber"), Integer).ToString())
Next

---But preferably you want to go directly to the record:

(If you have a primary key can be one key or compound key - see MSDN for more info)
Dim row as ds.Tables(0).Rows.Find("54")
If Not row is Nothing Then
Debug.WriteLine(DirectCast(row("OrderDescription"), String)
End If

(Or if you want to get a sub set of rows or dont have a primary key)
Dim rows as DataRow() = ds.Tables(0).Select("Cost=45.17")
For i as Integer = 0 to rows.Count - 1
Debug.WriteLine(DirectCast(row("ProductName"), String))
Next

Ive shown a few of the common ways people do things...sounds like you might want to check out Dino Espisitos book on ADO.NET - its worth the money. Things become even easier when you have a strongly typed dataset when trying to find something.
 
Well, it seems like you and I dont programme VB6 the same way, you dont have to step through all records when using the ado-control. But again, I may have tried to solve this problem the wrong way.

Anyway, thanks for your help, it cleared some of my thoughts. And of course you are right, I must study more on the ado.net, but you know, been using VB6 and ADO since it arrived, its a bit frustrating to have to learn "simple" things again in ado.net. ;)

/Kid Icarus
 
Back
Top