0

Hi everyone,

How to use session value during fetching values from database of that particular session value?

SqlDataAdapter adapterprice = new SqlDataAdapter("SELECT product.productid, product.productname, product.price, product.description FROM product where product.productid= Session["productid"] ", myconnection);

During writing code in such a way it is showing error..
Can any one help me in this..??

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by ruhi
0

You should write it like

SqlCommand selectCommand = new SqlCommand("SELECT product.productid, product.productname, product.price, product.description FROM product where product.productid = @productID", myConnection);

            selectCommand.Parameters.Add("@productID", SqlDbType.Int);

            selectCommand.Parameters[0].Value = int.Parse(Session["productid"].ToString());

            SqlDataAdapter adapterprice = new SqlDataAdapter(selectCommand);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.