Tuesday, March 30, 2010

Programmatic access to sqldatasource dataset

You can certainly do something like this. I programmatically created an SqlDataSource,
called the Select Method on it, retrieved the DataView, and converted the results to
a DataTable that I can manipulate as I see fit.



string connectionString = "...Northwind Connection String...";
string selectSql = "SELECT [CategoryID], [CategoryName] FROM [Categories]";

DataSourceSelectArguments args = new DataSourceSelectArguments();

SqlDataSource dataSource = new SqlDataSource(connectionString, selectSql);
DataView view = (DataView)dataSource.Select(args);

DataTable table = view.ToTable();

No comments: