I'm doing a couple of assumptions here, but I hope I'm on target.
If you just want the first column of the first row, you should use SqlCommand.ExecuteScalar instead of reading it into a dataset.
For instance:
using (var cn = new SqlConnection("..."))
{
using (var cmd = new SqlCommand("SELECT statusCode FROM table WHERE whatever", cn)
{
cn.Open();
return (string)cmd.ExecuteScalar();
}
}
(Notice the using statement if you don't know it. It automatically disposes the connection and command)
You could also look into using SqlCommand.ExecuteReader which returns an SqlDataReader. The latter is cleaner and has better performance than the dataset method too.
using (var reader = cmd.ExecuteReader())
{
while(reader.Read())
{
var value = reader.GetString(0);
}
}
Check? Do you want to check for the existence of columns or that a value was returned? – Bobby Dec 15 '11 at 10:12