Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8601355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:49:21+00:00 2026-06-12T01:49:21+00:00

I am trying to execute a stored procedure in asp.net. The stored procedure requires

  • 0

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:

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();
        }

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 "comLinkExhibitToTask.ExecuteNonQuery()"
outside the try is a good idea. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:49:22+00:00Added an answer on June 12, 2026 at 1:49 am

    The solution:

    var cnSaveTask = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString());
            try
            {
                var comLinkExhibitToTask = new SqlCommand("p_CaseFileTasksExhibitLinkAdd", cnSaveTask) { CommandType = CommandType.StoredProcedure };
                cnSaveTask.Open();
                comLinkExhibitToTask.Parameters.Add(new SqlParameter("@TaskID", SqlDbType.Int));
                comLinkExhibitToTask.Parameters.Add(new SqlParameter("@ExhibitID", SqlDbType.Int));
                comLinkExhibitToTask.Parameters.Add(new SqlParameter("@InvestigatorID", SqlDbType.Int));
    
                foreach (string exhibit in hidExhibitsIDs.Value.Split(','))
                {
                    comLinkExhibitToTask.Parameters["@TaskID"].Value = taskID;
                    comLinkExhibitToTask.Parameters["@ExhibitID"].Value = Convert.ToInt32(exhibit);
                    comLinkExhibitToTask.Parameters["@InvestigatorID"].Value = int.Parse(Session["InvestigatorID"].ToString());
    
                    comLinkExhibitToTask.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(0, ex.Source, ex.Message);
            }
            finally
            {
                if (cnSaveTask.State == ConnectionState.Open)
                {
                    cnSaveTask.Close();
                }
            }
    

    Since I was in a loop it kept adding parameters. So just declare the parameters outside the loop, and only pass the values in the loop. That way there are only 3 parameters, and the values will be passed in accordingly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that I'm trying to execute using Dapper that is
I am trying to call a stored procedure in an ASP.NET page and get
I'm trying to execute the following stored procedure in .net 4.5 PROCEDURE my_procedure (
So, I'm trying to use ODBC to execute a stored procedure in an SQL
In my Script Component, am trying to execute Stored Procedure => which return multiple
Im trying to execute a stored procedure and simply insert its results in a
I'm trying to execute a stored procedure (against SQL Server 2005 through the ODBC
I'm trying to execute a simple stored procedure with Spring/Hibernate using Annotations. Here are
I am trying to execute a procedure that returns a stored procedure. My version
I am trying to execute a stored procedure and place the data in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.