如何将字符串转换为int。 [英] how to convert string to int.
问题描述
如何将字符串转换为int。
在我的数据库表中,字段是整数字段。
ex:Masterindustryid int
我想从另一家餐桌公司获得Masterindustryid 3,6,9,45,67相关记录。
asp.net我的字符串如4,6,9,45,67
我想将字符串转换为整数并传递给数据库。
我的查询是:
选择c.id,c.name从公司c加入masterindustru mi on c。 industryid = mi.Masterindustryid其中c.industryid in(3,6,9,45,67)
动态地我使用存储过程传递一个字符串。
这里我有转换问题是字符串到int。
请帮帮我,
谢谢。
您可以使用提示使用逗号分隔值参数stri SQL IN子句中的ngs [ ^ ]让你的问题得到解决
转换为你的字符串为List< string>
string str = 1,2,3,4跨度>;
var lst = str.Split(' ,')。ToList();
然后尝试以下代码
< pre lang =c#>。其中(c = > lst.Contains(c.industryid))
希望这有帮助
你遇到转换问题,因为你的字符串包含逗号分隔的整数序列,而不是一个整数。您必须首先提取这些整数(您可以使用字符串.Split [ ^ ]方法)然后转换这些提取的整数。
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.
You can use the Tip Using comma separated value parameter strings in SQL IN clauses[^] to get your issue resolved
Convert to you string to List<string>
string str="1,2,3,4"; var lst=str.Split(',').ToList();
and then try the below code
.Where(c => lst.Contains(c.industryid))
Hope this helps
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.
这篇关于如何将字符串转换为int。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!