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

Posted on 2004-09-27
Last Modified: 2010-04-15
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??

Question by:sean-keys
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 15

Expert Comment

ID: 12165089
string strSQL = "SELECT product_price from t_products where product_id ="+ productID;
LVL 15

Accepted Solution

praneetha earned 50 total points
ID: 12165093
string strSQL = "SELECT product_price from t_products where product_id ="+ productID.ToString()

Author Comment

ID: 12165145
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" ";


LVL 15

Expert Comment

ID: 12165222
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'";

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question