Dataset - can't get my head around it!

CryoEnix

Well-known member
Joined
Jan 11, 2003
Messages
93
Location
Wrexham, Wales
Hi there guys, Ive managed to populate a dataset with a table (from a SQL query), and Im trying to access the data in it directly instead of binding it to a dataGrid. How would I go about this? Say I had the following Table:

ID Name Password
1 Bob BobsPassword
2 Colin ColinsPassword

I want something like:

dataG.Column["name"].Row[0] to equal "bob"
dataG.Column["id"].Row[1] to equal "2"

I cant seem to navigate my way through the web of properties myself - please help!
 
Never mind peeps, after perusing the net some more Ive found the solution. I need to create DataRows to handle the data, row at a time. Thanks anyway!
 
No you dont neet to create DataRows.

Code:
dataG.Rows[0]["Name"]
has the value of the "Name" column in the first datarow
 
FZelle - cheers for the code. It didnt work, but after a bit off playing with it it was fine like this:

dataG.Tables[0].Rows[0]["Name"]

The Tables[0] part was omitted - do you know what the Tables index actually refers to? Id imagine there should only be two dimensions for a table...
 
Every dataset has a collection of datatable. So the index in the Tables[0] refer to the first table filled in the dataset. If I remember correctly, you could also access it using Tables["yourtablename"]. This way is easier to be certain which datatable youre accessing.

Try reading MSDN for the structure of DataSet. Youll find enough reference to get you started.
 
Back
Top