This seems like such a silly question, but I haven't found the answer yet.
How do I get a single value from a DataSet? Like, if the DataSet has a table "TableX" which has a field/column "ValueX", then how do I get "ValueX" for a given row? I've only been using DataSets to bind whole columns and stuff thus far.
If you are returning a 1x1 result (e.g. SELECT Count(*) FROM Table1), then you should look at using the .ExecuteScalar() method instead of using a DataSet. You can find it on all of the providers (SqlCommand, OleDbCommand).
Incidentally, have you checked out the Microsoft Data Application Block? This will often get you down to one line of code for a statement like above.
LDAP Programming Help
It's actually a whole row worth of stuff assigned to various controls. I typically use an SqlDataReader for the task, but I'm worried about maintaining a forward-only structure for my current needs. There HAS to be a simple way to just grab a piece of data!
PS-Cool link. Looks handy.
Why are you worried about using a SqlDataReader? Just open it as late as possible, and close it as soon as possible.
This posting is provided "AS IS" with no warranties, and confers no rights.
Well, I'm not sure of the order I will be calling the fields, and I don't know whether I'll be able to access fieldX if I already move past it to fieldZ. Can I?
I've run into problems binding an SqlDataReader to multiple controls before because of the forward-only nature of the reader (I had two drop downs which both had the same "color" data). I'm worried that I'll run into the same situation with what I'm doing now.
In a nutshell, I want my controls' binds to be independant of any sort of required sequencing such that rearranging the binds or adding an out of sequence control won't break the system.
Regardless, it would be nice to know how to access a single value of a DataSet.
Just so you know :)
ds.tables(0).rows(0).item(0).tostring - return the first record in the first row of the first table.
Brian O'Connell (MCAD) - http://www.systemdotweb.com