[英]My sql question error list not convert Int32 in c# mvc
I need to send list and add my project but this is not working.我需要发送列表并添加我的项目,但这不起作用。 I don't understand this station
看不懂这个站
This is error message:这是错误信息:
System.InvalidCastException: parameter value of`List ' 1 could not be converted to Int32.'
System.InvalidCastException: 无法将`List '1 的参数值转换为 Int32。'
InvalidCastException: must be implemented by the IConvertible object.
InvalidCastException:必须由 IConvertible 对象实现。
This is my code in sql part:这是我在 sql 部分的代码:
ServiceAw.AddParameter("@CustID", SqlDbType.Int, value.CustomerIDS)
.
.
string cmd = @"SELECT Name,SurName from WebUsers,";
cmd += @" (select Email from WebUsers as WUS where WUS.UserID = FixID) as UserMail,Fixed";
cmd += @" where S.Ref <> 0 ";
if (value.CustomerIDS != null)
{
int i = 0;
cmd += @" and ST.Ref NOT IN (";
foreach (int item in value.CustomerIDS)
{
if (i == 0) { cmd += $"'{item}'"; } else { cmd += $",'{item}'"; }
i++;
}
cmd += @" )";
}
This is my class:这是我的课:
public class SpecialInput
{
public int CustomID { get; set; }
public int UserID { get; set; }
public List<int> CustomerIDS{ get; set; }
}
Firstly, This line cause the error:首先,这一行导致错误:
ServiceAw.AddParameter("@CustID", SqlDbType.Int, value.CustomerIDS)
SqlDbType.Int is type Int , While you are passing List type value.CustomerIDS SqlDbType.Int是Int类型,当您传递List 类型value.CustomerIDS
Secondly, I guess you wanna pass the list of CustomerIds into stored Procedure, You should use some techniques mentioned in this tutorial .其次,我猜您想将 CustomerIds 列表传递到存储过程中,您应该使用本教程中提到的一些技术。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.