Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving a field value from a Dataset
Message
 
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:
00682361
Views:
26
This message has been marked as the solution to the initial question of the thread.
>1) Can I do this in just 1 line?:
>
> dsCustomers.Tables["Customers"].Rows[1].[] ..?
>

Just type:
dsCustomers.Tables["Customers"].Rows[1]["cCustName"].ToString();
>2)I'm using a hard coded "1", how do I get the current row, couldn't find a property for that either.
>

See Message #667679 for an explanation of getting the current row.


>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
>>
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform