Thursday, March 1, 2012

How to Convert SqlDataSource to DataTable and DataView in C#

Sometimes I want to use SqlDataSource  returned data programmatically and here is how you can do this,

In this example I will assume that SqlDataSource  ID is SqlDataSource1 which is the default ID:
DataSourceSelectArguments args = new DataSourceSelectArguments();
DataView view = SqlDataSource1.Select(args) as DataView; 
DataTable dt = view.ToTable();