Invalid attempt to call Read when reader is closed,base {System.SystemException} = {"Invalid attempt to call Depth when reader is closed."}

421 views Asked by At

getting this exception while retrieving the data using data reader from stored procedure. Invalid attempt to call Depth when reader is closed.Invalid attempt to call Read when reader is closed,base {System.SystemException} = {"Invalid attempt to call Depth when reader is closed."

base {System.SystemException} = {"Invalid attempt to call HasRows when reader is closed."}
base {System.SystemException} = {"Invalid attempt to call FieldCount when reader is closed."}
  public DataSet FilteredGetProductsSearch(string ProductName,  int PageSize,int PageIndex)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ProductId");
            dt.Columns.Add("ProductPriceId");
            dt.Columns.Add("Name");
            dt.Columns.Add("UrlRewrite");
            dt.Columns.Add("Description");
            dt.Columns.Add("Price");
            dt.Columns.Add("Size");
            dt.Columns.Add("Stock");
            dt.Columns.Add("Weight");
            dt.Columns.Add("MediaFilename");
            dt.Columns.Add("ThumbnailFilename");
            dt.Columns.Add("ProductName");
            dt.Columns.Add("ProductDescription");

        using (IDataReader reader = SPs.FilteredGetProductsSearch(ProductName,PageSize, PageIndex).GetReader())
        {

            while (reader.Read())
            {
                DataRow dr = dt.NewRow();
                dr["ProductId"] = reader["ProductId"];
                dr["ProductPriceId"] = reader["ProductPriceId"];
                dr["Name"] = reader["Name"];
                dr["UrlRewrite"] = reader["UrlRewrite"];
                dr["Description"] = reader["Description"];
                dr["Price"] = reader["Price"];
                dr["Size"] = reader["Size"];
                dr["Stock"] = reader["Stock"];
                dr["Weight"] = reader["Weight"];
                dr["MediaFilename"] = reader["MediaFilename"];
                dr["ThumbnailFilename"] = reader["ThumbnailFilename"];
                dr["ProductName"] = reader["ProductName"];
                dr["ProductDescription"] = reader["ProductDescription"];
                dt.Rows.Add(dr);
            }
        }
        DataSet ds = new DataSet();
        ds.Tables.Add(dt);
        return ds;

    }
0

There are 0 answers