sangeetha k

sangeetha k

  • NA
  • 207
  • 51.3k

Fetchhing price from db to textbox

Oct 12 2017 12:50 AM
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();
}
 

Answers (11)