I am trying to insert a list of IDs, but I am receiving the above error. Please help.
Here is my code:
public static int StringToInt(string message2) { int message; int.TryParse(message2, out message); //int v = Convert.ToInt32(message); return message;
} public void CreateGroupRestriction(UserData userData, string message2) { do { string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("dbo.CreateRestriction", con); cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramRoleName = new SqlParameter(); paramRoleName.ParameterName = "@RoleName"; paramRoleName.Value = userData.RoleName; cmd.Parameters.Add(paramRoleName);
SqlParameter paramRestrictionEntityTypeCode = new SqlParameter(); paramRestrictionEntityTypeCode.ParameterName = "@RestrictionEntityTypeCode"; paramRestrictionEntityTypeCode.Value = "O"; cmd.Parameters.Add(paramRestrictionEntityTypeCode);
SqlParameter paramRestrictionEntityID = new SqlParameter(); paramRestrictionEntityID.ParameterName = "@RestrictionEntityID"; Converter<string, int> converter = new Converter<string, int>(StringToInt); paramRestrictionEntityID.Value = Array.ConvertAll(message2.Split(','), converter); cmd.Parameters.Add(paramRestrictionEntityID);
SqlParameter paramExclude = new SqlParameter(); paramExclude.ParameterName = "@Exclude"; paramExclude.Value = "0"; cmd.Parameters.Add(paramExclude);
con.Open(); cmd.ExecuteNonQuery(); } } while
(message2 != ""); }
The error occurs on this line: paramRestrictionEntityID.Value = Array.ConvertAll(message2.Split(','), converter);