dd7beckham
New Member
I am trying to execute a stored procedure in asp.net. The stored procedure requires 3 parameters, all 3 are ID's(ints). The 3 parameters are : TaskID, ExhibitID, and InvestigatorID.I have a hidden field that contains an array of ExhibitID's that came from a javascript function.My question is how do I get the query to execute as I am looping through the array?Here is an example of my stored procedure:\[code\]var cnSaveTask = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString()); var comLinkExhibitToTask = new SqlCommand("p_CaseFileTasksExhibitLinkAdd", cnSaveTask) { CommandType = CommandType.StoredProcedure }; foreach (string exhibit in hidExhibitsIDs.Value.Split(',')) { comLinkExhibitToTask.Parameters.AddWithValue("@TaskID", taskID); comLinkExhibitToTask.Parameters.AddWithValue("@ExhibitID", Convert.ToInt32(exhibit)); comLinkExhibitToTask.Parameters.AddWithValue("@InvestigatorID", int.Parse(Session["InvestigatorID"].ToString())); } try { cnSaveTask.Open(); comLinkExhibitToTask.ExecuteNonQuery(); }\[/code\]It is not working in my DB though. Nothing gets added. My guess is that since it is iterating and not executing, it just keeps replacing the "exhibitID" everytime then eventually tries to execute it. But I don't think just adding \[code\]"comLinkExhibitToTask.ExecuteNonQuery()"\[/code\]outside the try is a good idea. Any suggestions?