Working with a single record resultset vs multi record

  • Thread starter Thread starter Aussie Rules
  • Start date Start date
A

Aussie Rules

Hi,

In all my coding to date, i have been dealing with multiple results in my
dataset, looping through them with



SqlDataAdapterContactProfile.Fill(contact, "Profile")

For Each pRow In contact.Tables("Profile").Rows

label1.text = prow("fieldname")

Next


I now have a situation where I only return a single record, and want to know
how i should deal with this situation. There is no point having a for each
loop
as there is only the one row.

What code should I have so that I can access the single record result set

Thanks
 
Aussie said:
Hi,

In all my coding to date, i have been dealing with multiple results in my
dataset, looping through them with

You mean a single result with multiple rows. Multiple results would mean
that you would have multiple Table objects in the DataSet.
SqlDataAdapterContactProfile.Fill(contact, "Profile")

For Each pRow In contact.Tables("Profile").Rows

label1.text = prow("fieldname")

Next


I now have a situation where I only return a single record, and want to
know
how i should deal with this situation. There is no point having a for
each loop
as there is only the one row.

What code should I have so that I can access the single record result set

Just access the first row (index 0):

label1.Text = contact.Tables("Profile").Rows(0).Item("fieldname")

or

label1.Text = contact.Tables("Profile").Rows(0)("fieldname")


If you want to access more than one field, you might want to create a
reference to the row:

Dim profile As DataRow = contact.Tables("Profile").Rows(0)
label1.Text = profile("fieldname")
 
Aussie said:
Hi,

In all my coding to date, i have been dealing with multiple results in my
dataset, looping through them with



SqlDataAdapterContactProfile.Fill(contact, "Profile")

For Each pRow In contact.Tables("Profile").Rows

label1.text = prow("fieldname")

Next


I now have a situation where I only return a single record, and want to
know
how i should deal with this situation. There is no point having a for
each loop
as there is only the one row.

What code should I have so that I can access the single record result set

I think this link will put you into the ballpark.

<http://www.aspfree.com/c/a/MS-SQL-Server/Pulling-Information-using-DataAdapter-with-ADONET/2/>

http://preview.tinyurl.com/ysos8p
 
Sorry,

This is not meant as a correction or whatever, just attached to the wrong
thread while your message was open, should have been to the main thread.

Cor
 
Cor said:
Darnold

There are AFAIK only two methods to Find a row. That is using the DataView
which returns the position in the dataview and the find in the
datarowcollection which returns a datarow.
All others return a collection of rows.

http://www.vb-tips.com/dbpages.aspx?ID=c254bc74-fe91-46b3-836d-13dccb86d378

I hope this helps,

Cor

Perhaps you replied in the wrong thread? He's not trying to find
anything at all. He only has a single row, so it's not very hard to find
it...
 
You are right

Göran Andersson said:
Perhaps you replied in the wrong thread? He's not trying to find anything
at all. He only has a single row, so it's not very hard to find it...
 
Back
Top