Sunday, March 25, 2012

Accessing data in a column

I have a SQLDataSource returning data for a formview. This should be a simple question that I cannot find an answer to. The SQLDataSource is returning only one row of data. How do I access the value of one of the columns?

Thanks for the information.

The following code example iterates through aDataReader object, and returns two columns from each row.

SqlDataReader reader = command.ExecuteReader();if (reader.HasRows)while (reader.Read()) Console.WriteLine("\t{0}\t{1}", reader.GetInt32(0), reader.GetString(1));else Console.WriteLine("No rows returned.");reader.Close();
|||So should I just use a datareader (built in a separate class file) instead of using the SQLDataSource?|||SQLDataSource is always used to bind to a control . If you want to fetch data from DB , DataReader is a better choice .

No comments:

Post a Comment