I want to populate a gridview with table data from SQL. I tried just returning my SqlDataReader object and using it as my datasource, but I am getting errors that the reader has been closed. I wanted to convert this to a DataSet and just return a dataset, but I couldn't find an easy way to convert the row data to a dataset. I've also read that DataSets are dead in .NET 3.5/4.0, is this true?
Here's my Data Layer method. It would be awesome if I could return something useable as a datasource:
public SqlDataReader GetSites()
{
SqlConnection sqlCon = null;
SqlDataReader rdr = null;
try
{
sqlCon = new SqlConnection(StoredProcedures.conString);
sqlCon.Open();
SqlCommand cmd = new SqlCommand("GetSites", sqlCon);
cmd.CommandType = CommandType.StoredProcedure;
rdr = cmd.ExecuteReader();
return rdr;
}
finally
{
if (sqlCon != null)
{
sqlCon.Close();
}
//if (rdr != null)
//{
// rdr.Close();
//}
}
}