Invalid attempt to call Read when reader is closed while retrieving data using datareader from stored procedure

StackOverflow https://stackoverflow.com/questions/20953253

質問

Invalid attempt to call Read when reader is closed. while invoking the data from stored procedure by using datareader the while loop was terminated without executing,the stored procedure from subsonic dal(wcf)

using (IDataReader reader = SPs.GetProductsSearch(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;

    }`
 public static StoredProcedure GetProductsSearch(string name, int? PageSize, int? PageIndex)
    {
        SubSonic.StoredProcedure sp = new SubSonic.StoredProcedure("Test_Get_Products_Search", DataService.GetInstance("Echemist"), "dbo");

        sp.Command.AddParameter("@SearchName", name, DbType.AnsiString, null, null);        

        sp.Command.AddParameter("@PageSize", PageSize, DbType.Int32, 0, 10);

        sp.Command.AddParameter("@PageIndex", PageIndex, DbType.Int32, 0, 10);

        return sp;
    }

    //ProductId stored procedure------------------------------------------------------------------------------------------
    public static StoredProcedure GetProductsByProductId(int ProductId)
    {
        SubSonic.StoredProcedure sp = new SubSonic.StoredProcedure("Get_ProductsByProductId", DataService.GetInstance("Echemist"), "dbo");

        sp.Command.AddParameter("@ProductId", ProductId, DbType.Int32, null, null);

        return sp;
    }

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top