I have a function that runs an SQL query, creates a DataTable from it, then creates a DataSourceResult based on the DataSourceRequest parameters.
I would like create a filteredDataTable with the results of filteredDataSourceResult.
How can I do that? My code is below:
public ActionResult GrabFiltersApplytoQueryProcessFilteredResults([DataSourceRequest]DataSourceRequest request){
String sqlConnectionString = db.Database.Connection.ConnectionString;
SqlConnection sqlConnection = new SqlConnection(sqlConnectionString); sqlConnection.Open();
string sqlCommandText = "";
sqlCommandText = "execute sp_query";
SqlCommand sqlCommand = new SqlCommand(sqlCommandText, sqlConnection); SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = sqlCommand;
DataTable dataTable = new DataTable();
dataAdapter.Fill(dataTable);
sqlConnection.Close();
DataSourceResult filteredDataSourceResult = dataTable.ToDataSourceResult(request);
//copy columns
DataTable filteredDataTable = dataTable.Clone();
//how do I add filteredDataSourceResult.data into filteredDataTable?
...
// other processing that requires a DataTable
...
}
Thanks,
Peter