Solved

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

Posted on 2004-09-27
4
198 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 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