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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fomat Json objects 6 28
Achieve json result 2 65
XML & .net 5 41
C# parent child form 5 17
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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now