Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2004-09-27
Medium Priority
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 200 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

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.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…

715 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