Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 


adodc1.recordset!fieldname

 

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

 

Anyone?

 

Thanks in advance. :-\

 

Kid Icarus

Posted

Didn't follow your question because I've 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")

 

I'm way off on the syntax above, but it's along those lines, I'm almost always use strongly typed datasets (runs faster, get intellisense, lots of other advantages), and I've 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 it's just an example, hope it helps.

Posted

The

 

 

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

 

 

worked fine, but how do I know what row-number I´m currently at? You used 5 in your example, but the program must read the current row number in the dataset... how is this done?

 

(I have a datagrid connected to a dataset. When I click on a row, I want the "sub"-datagrid's dataset requery, selekting records based on a value from the first dataset. Hope this is clear.)

Posted

In old school you did something like (again can't 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 don't 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

 

I've shown a few of the common ways people do things...sounds like you might want to check out Dino Espisito's book on ADO.NET - it's worth the money. Things become even easier when you have a strongly typed dataset when trying to find something.

Posted

Well, it seems like you and I don't programme VB6 the same way, you don't 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...