Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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
0
sean-keys
Asked:
sean-keys
  • 3
1 Solution
 
praneethaCommented:
string strSQL = "SELECT product_price from t_products where product_id ="+ productID;
0
 
praneethaCommented:
string strSQL = "SELECT product_price from t_products where product_id ="+ productID.ToString()
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now