Reputation: 470
This is my code
var s = from p in db.tblTotalFees
where p.Class == ClassDropDownList.SelectedItem.Value && p.StudentID == Convert.ToInt32(StudentNameDropDownList.SelectedValue)
select p;
DataTable dt = new DataTable();
How can i convert p into a datatable and store it in dt???
Upvotes: 1
Views: 606
Reputation: 236308
You can use CopyToDataTable()
extension method which is described on MSDN How to: Implement CopyToDataTable Where the Generic Type T Is Not a DataRow. Usage:
var selectedClass = ClassDropDownList.SelectedItem.Value;
int id = Convert.ToInt32(StudentNameDropDownList.SelectedValue);
var query = from p in db.tblTotalFees
where p.Class == && selectedClass
p.StudentID == id
select p;
DataTable dt = query.CopyToDataTable(); // here
Or you can use pure ADO.NET - create SqlCommand and fill table with SqlDataAdapter.
Upvotes: 1