Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving a field value from a Dataset
Message
From
25/07/2002 01:16:10
 
 
To
24/07/2002 20:02:15
Jorge Haro
Independent Consultant
Juarez, Mexico
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00682350
Message ID:
00682408
Views:
18
This message has been marked as a message which has helped to the initial question of the thread.
Jorge,

In addition to Cathi's reply, I'd like to add something and hope it doesn't further confuse you. Another option when using DataSets is to have .NET generate a typed dataset for you (right click in your .xsd and click on the Generate option). The syntax is easier to handle. Your example would then be:
  dsCustomers.Customers.Rows[0].cCustName.ToString(); 
A typed DataSet allows Intellisense to kick in for both your table names and your column names, which you don't get with just a regular DataSet. Also notice that I used a Rows[0], rather than [1]. Don't forget that the Rows collection is zero-based.

~~Bonnie

>Update:
>
>
>DataRow myRow ;
>myRow = dsCustomers.Tables["Customers"].Rows[1] ;
>Console.WriteLine( myRow["cCustName"].ToString() );
>
>This works but it has a couple of problems:
>
>1) Can I do this in just 1 line?:
>
>
dsCustomers.Tables["Customers"].Rows[1].[] ..?
>
>2)I'm using a hard coded "1", how do I get the current row, couldn't find a property for that either.
>
>>This is probably terribly simple but I can't seem to find it anywhere in the docs. How do I retrieve a field value from a dataset, the examples use something like:
>>
>>
>>foreach(DataTable tabla in dsCustomers.Tables)
>>   foreach(DataRow rowCustomer in tabla.Rows )
>>   {
>>      Console.WriteLine(rowCustomer["cCustName"]);
>>   }
>>
>>What if I want to just retrieve the value of a field from the current row?
>>I've tried
>>
>>   MyDataSet.Tables["CUSTOMERS"].Columns["cCustName"]
>>
>>But that gives me the name of the column, I suppose it's like calling ToString for the Column object. So I looked for a Column property similar to ADO's Value property, and I couldn't find one listed in DataColumn members, strange that you can get all sorts of info about the column except for the actual value.
>>
>>I've also tried using the Rows object but couldn't figure out the correct syntax, any help would be appreciated.
>>
>>In classic ADO all I had to do was:
>>
>>   MyRecordSet.Fields("cCustName").Value
>>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform