i want fetch a single data named price from db to textbox but it yeilds 0
#My Stored procedure
GO
alter PROCEDURE [dbo].[spGetPrice]
@productId as int,
@categoryId as int,
@price as int output
AS
BEGIN
SELECT @price=price from product04 where product_id=@productId and category_id=@categoryId
END
GO
#My dll
conn.Open();
SqlCommand cmd = new SqlCommand("spGetPrice", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@productId", DbType.Int32).Value = productId;
cmd.Parameters.AddWithValue("@categoryId", DbType.Int32).Value = categoryId;
cmd.Parameters.Add("@price", SqlDbType.Int);
cmd.Parameters["@price"].Direction = ParameterDirection.Output;
price=Convert.ToInt32( cmd.ExecuteScalar());
#My bll int price;
try
{
price = dal.GetPrice(categoryId, productId);
return price;
}
catch
{
throw;
}
#code behind protected void btnGetDetails_Click(object sender, EventArgs e)
{
int productId=Convert.ToInt32(txtProductid.Text);
int categoryId=Convert.ToInt32(txtCategoryId.Text);
txtPrice.Text = bll.GetProductPrice(categoryId, productId).ToString();
}
11 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sangeetha kPosted Oct 12, 2017, 8:09 AM
Ankit SharmaPosted Oct 12, 2017, 4:07 AM
Ramesh PalanivelPosted Oct 12, 2017, 2:54 AM
sangeetha kPosted Oct 12, 2017, 2:41 AM
sangeetha kPosted Oct 12, 2017, 2:41 AM
sangeetha kPosted Oct 12, 2017, 2:40 AM
Amit GuptaPosted Oct 12, 2017, 2:32 AM
sangeetha kPosted Oct 12, 2017, 2:11 AM
Ramesh PalanivelPosted Oct 12, 2017, 1:29 AM
sangeetha kPosted Oct 12, 2017, 1:21 AM
Ramesh PalanivelPosted Oct 12, 2017, 1:00 AM