I am trying to iterate through a hiddenfield that has been populated with fileID’s by javascript. I’ve tried it like this :
foreach(string exhibit in hidExhibitsIDs.Value.Split(','))
{
comLinkExhibitToTask.Parameters.AddWithValue("@ExhibitID", exhibit);
}
but I’m not sure if it will in the id as a string to the db.(my property in my DB is int so I’m guessing that is why my stored procedure isn’t working.) I am trying to iterate the loop as an int like this :
foreach (int exhibit in hidExhibitsIDs.Value)
{
comLinkExhibitToTask.Parameters.AddWithValue("@ExhibitID", exhibit);
}
I’ve tried doing int.Parse(hidExhibitID's.Value) etc but it gives me the error above.
Your
foreachloop won’t just magically cast a comma delimited list of numbers into an enumeration of integers. You were on the right track before using theSplit()method ofString. However, you’ll then need to convert each value to an integer usingConvert.ToInt32().Something like: