I have a SqlDataReader from a SQL Server command and want I to show in a DataDridView with this code:
SqlDataReader dr=product.RetriveDetailsOfOneProduct();
DataTable dt = new DataTable();
dt.Load(dr);
DataGrid.DataSource = dr;
I checked it using breakpoints that my SqlDataReader has rows but when loading it into DataTable, it is empty (with no rows)
How can I fix this?
And it is function of my DataAccess class where SqlDataReader is returned:
internal SqlDataReader RetriveDetailsOfOneProduct(product product)
{
string RetriveQuery = string.Format("SElect person.F_Name as N'Name ',person.L_Name as N'LastName',borrow.Person_Identity as N'Identity',borrow.T_Date as 'Date1', borrow.B_Date as 'Date2' from BorrowTable borrow Inner join PersonTable person on borrow.Product_Name=N'{0}' and person.Person_identity=borrow.Person_Identity ", product.Productname);
SqlCommand cmd = new SqlCommand(RetriveQuery, conn);
// conn.Close(); //if i close the Connection(conn) it runs into error
return(cmd.ExecuteReader());
}
using(){}for auto disposing