2010/03/26

[ASP.NET]The DataSourceMode of SqlDataSource

By default, the DataSourceMode of the SqlDataSource is DataSet. Here is how to retrieve the dataset from the SqlDataSource control:
DataTable dt = ((DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty)).ToTable();
or
DataTable dt = ((DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty)).Table;

If you set the DataSourceMode to DataReader, here is how to read the data:
IDataReader reader = (IDataReader)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
while (reader.Read())
{
//your code here
}
reader.Close();
reader.Dispose();

No comments:

Post a Comment