Solved

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

Posted on 2004-09-27
4
197 Views
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??

Thanks,
Sean
0
Comment
Question by:sean-keys
  • 3
4 Comments
 
LVL 15

Expert Comment

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

Accepted Solution

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

Author Comment

by:sean-keys
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" ";


Thanks
Sean  

0
 
LVL 15

Expert Comment

by:praneetha
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'";
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

832 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