If we have filled a DataSet using a select query in C#, how can we read the column values?
I want to do something like this:
string name = DataSetObj.rows[0].columns["name"]
What would the correct syntax look like to achieve my goal?
foreach(var row in DataSetObj.Tables[0].Rows)
{
Console.WriteLine(row["column_name"]);
}
If you already have a dataset, it's something like this;
object value = dataSet.Tables["MyTable"].Rows[index]["MyColumn"]
If you are using a DataReader:
using (SqlCommand cmd = new SqlCommand(commandText, connection, null))
{
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
testID = (int)reader["id"];
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With