You also need to check query is returning data or not , you are facing issue because you are trying to access datarow data which is not present. I hope you got my point.
dsOrderDetail = bal.getRecordDisplay(product_id, category_id);
if(dsOrderDetail !=null && dsOrderDetail.Table.Count > 0 && dsOrderDetail.Table.Rows.Count >0)
{
lblProdName.Text = dsOrderDetail.Tables[0].Rows[0]["Product_Name"].ToString() + "<br/>";
lblProdId.Text = dsOrderDetail.Tables[0].Rows[1]["Product_Id"].ToString() + "<br/>";
lblProdDesc.Text = dsOrderDetail.Tables[0].Rows[2]["Description"].ToString() + "<br/>";
lblCtyId.Text = dsOrderDetail.Tables[0].Rows[3]["Category_id"].ToString() + "<br/>";
lblPrice.Text = dsOrderDetail.Tables[0].Rows[4]["Price"].ToString() + "<br/>";
lblAblty.Text = dsOrderDetail.Tables[0].Rows[5]["Availability"].ToString() + "<br/>";
}
there is issue with you stored procedure
SELECT * FROM product04 where product_id=345 and category_id=2346
instead of this line of query it should be
CREATE PROCEDURE [dbo].[sp_Productselect]
@product_id as int,
@category_id as int
AS
BEGIN
SELECT * FROM product04 where product_id=@product_id and category_id=@category_id
END
GO
there are other thing in you code , you should use “using” for connection to dispose it.
public DataSet getRecordDisplay(int product_id,int category_id)
{
...
using( SqlConnection con = new SqlConnection(connectionstring))
{
}
...
}
1
solved Please tell me where i am wrom how to correct it : [closed]