简体   繁体   中英

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.'

InvalidCastException: must be implemented by the IConvertible object.

This is my code in sql part:

      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

Secondly, I guess you wanna pass the list of CustomerIds into stored Procedure, You should use some techniques mentioned in this tutorial .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM