How do I make a int variable part of a string.

Here is what I have, that doesn’t work.


public void GetProductPrice(int productID)
            {
                  int ID = productID;
                  string strSQL = "SELECT product_price from t_products where product_id = productID";



How can I make it so where the string reads productID it will be the value that was passed in??

Thanks,
Sean
sean-keysAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
praneethaConnect With a Mentor Commented:
string strSQL = "SELECT product_price from t_products where product_id ="+ productID.ToString()
0
 
praneethaCommented:
string strSQL = "SELECT product_price from t_products where product_id ="+ productID;
0
 
sean-keysAuthor Commented:
What if I wanted a variable to be in the middle of a string, would this be correct?


strSQL = " "SELECT" + productID.ToString() + " from t_products where product_id = 2" ";


Thanks
Sean  

0
 
praneethaCommented:
yep but it is a bad example bcz select something is from database..

string strSQL = "SELECT product_price from t_products where product_id ="+ productID.ToString()+" and product_type='try'";
0
All Courses

From novice to tech pro — start learning today.