Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
how to convert string to int.
In my database table filed is integer field.
ex: Masterindustryid int

I want to get Masterindustryid 3,6,9,45,67 related records from another table company.

asp.net my string like "4,6,9,45,67"

I want to convert string to integer and pass to database.

my query is:

select c.id,c.name from company c join masterindustru mi on c.industryid=mi.Masterindustryid where c.industryid in(3,6,9,45,67)

Dynamically I passed a string using stored procedure.

Here I got convertion problem is string to int.

Please help me,
Thank you.
Posted
Updated 11-Aug-14 21:08pm
v2
Comments
Kishor Deshpande 12-Aug-14 3:10am    
How you are passing the values in in clause?

Would like to see the ADO.NET code involing this query...
Kumarbs 12-Aug-14 3:12am    
What would you like to convert cid in select statement or something else?
NagaRaju Pesarlanka 12-Aug-14 3:24am    
I want to pass dynamic parameter as a string type to stored procedure, like industry="3,5,8,9,87,34"
but my db field is integer, How can I pass where in clase.
Kumarbs 12-Aug-14 3:27am    
Even if you use the IN operator in where clause you will get the output. Is there any specific reason to convert to int?
NagaRaju Pesarlanka 12-Aug-14 3:40am    
my db field is integer, it is mandatory for this query.

You can use the Tip Using comma separated value parameter strings in SQL IN clauses[^] to get your issue resolved
 
Share this answer
 
Comments
NagaRaju Pesarlanka 12-Aug-14 4:09am    
Think you this link code working...
Convert to you string to List<string>

C#
string str="1,2,3,4";
var lst=str.Split(',').ToList();


and then try the below code
C#
.Where(c => lst.Contains(c.industryid))


Hope this helps
 
Share this answer
 
v2
Comments
NagaRaju Pesarlanka 12-Aug-14 3:25am    
I want to pass dynamic parameter as a string type to stored procedure, like industry="3,5,8,9,87,34"
but my db field is integer, How can I pass where in clase.
Jameel VM 12-Aug-14 4:13am    
use dynamic keyword
You got a conversion problem because your string contains a comma separated sequence of integers, not a single one. You have to first extract those integers (you may use the String.Split[^] method) and then convert such extracted integers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900