Solved

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

Posted on 2004-09-27
4
193 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
Comment Utility
string strSQL = "SELECT product_price from t_products where product_id ="+ productID;
0
 
LVL 15

Accepted Solution

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

Author Comment

by:sean-keys
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

16 Experts available now in Live!

Get 1:1 Help Now