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..??

Recommended Answers

All 2 Replies

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);

Thank you very much...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.