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 6474049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:32:25+00:00 2026-05-25T06:32:25+00:00

Each survey has multiple questions (10) and each question has it’s own rating. At

  • 0

Each survey has multiple questions (10) and each question has it’s own rating. At the moment I can only insert a rating for each question one at a time. I’m trying to create one form so that I can add a rating to each question at the same time.

The issue I’m running into is that the form only enters the rating for the first question and runs into an error at the second instance of: ‘throw new ApplicationException(“Data error.”);’

Each question needs to keep the selected survey ID to identify which survey it belongs to.

===== Code Behind =====

        protected void AddRatingBTN_Click(object sender, EventArgs e)
        {

            if (DropDownListSurvey.SelectedValue == "Select")
            {
                //Label1.Text = "hi";
                return;
            }

            string connectionString = WebConfigurationManager.ConnectionStrings["DBConnectionString1"].ConnectionString;


            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("InsertRating", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("@Rating_ID", SqlDbType.Int, 7));
            cmd.Parameters["@Rating_ID"].Direction = ParameterDirection.Output;


            cmd.Parameters.Add(new SqlParameter("@Question_ID", SqlDbType.Int));
            cmd.Parameters["@Question_ID"].Value = 1000;

            cmd.Parameters.Add(new SqlParameter("@Survey_ID", SqlDbType.Int));
            cmd.Parameters["@Survey_ID"].Value = Convert.ToInt32(DropDownListSurvey.SelectedValue.ToString());

            cmd.Parameters.Add(new SqlParameter("@Score", SqlDbType.Char, 5));
            cmd.Parameters["@Score"].Value = Question_1.Text;

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
               // txtRating_ID.Text = Convert.ToString(cmd.Parameters["@Rating_ID"].Value);

            }
            catch (SqlException err)
            {
                // Replace the error with something less specific.
                // You could also log the error now.
                throw new ApplicationException("Data error.");
            }
            finally
            {
                con.Close();
            }

            cmd.Parameters.Add(new SqlParameter("@Rating_ID", SqlDbType.Int, 7));
            cmd.Parameters["@Rating_ID"].Direction = ParameterDirection.Output;

            cmd.Parameters.Add(new SqlParameter("@Question_ID", SqlDbType.Int));
            cmd.Parameters["@Question_ID"].Value = 1001;

            cmd.Parameters.Add(new SqlParameter("@Score", SqlDbType.Char, 5));
            cmd.Parameters["@Score"].Value = Question_2.Text;

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                // txtRating_ID.Text = Convert.ToString(cmd.Parameters["@Rating_ID"].Value);

            }
            catch (SqlException err)
            {
                // Replace the error with something less specific.
                // You could also log the error now.
                throw new ApplicationException("Data error.");
            }
            finally
            {
                con.Close();
            }

            cmd.Parameters.Add(new SqlParameter("@Rating_ID", SqlDbType.Int, 7));
            cmd.Parameters["@Rating_ID"].Direction = ParameterDirection.Output;

            cmd.Parameters.Add(new SqlParameter("@Question_ID", SqlDbType.Int));
            cmd.Parameters["@Question_ID"].Value = 1002;

            cmd.Parameters.Add(new SqlParameter("@Score", SqlDbType.Char, 5));
            cmd.Parameters["@Score"].Value = Question_3.Text;

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                // txtRating_ID.Text = Convert.ToString(cmd.Parameters["@Rating_ID"].Value);

            }
            catch (SqlException err)
            {
                // Replace the error with something less specific.
                // You could also log the error now.
                throw new ApplicationException("Data error.");
            }
            finally
            {
                Response.Redirect(Request.RawUrl);
                con.Close();
            }
        }
    }
}
  • 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-05-25T06:32:25+00:00Added an answer on May 25, 2026 at 6:32 am

    This code brings back some old memories, not really great ones unfortunately. Anyway, I think the problem is that you’re adding the parameters multiple times to the same command object. Your first execute works because you have the correct number of parameters. In the prep for the second run, you’re adding them again, but the cmd still has the old parameters still there. If you remove the .Add calls after the first time it should work.

    You should look into more modern ways of handling data access. Check out LINQ-to-SQL at the very least.

    I’ll also add a few design pointers. Based on the data you’re saving, you probably want to have the inserts wrapped in a single transaction, which is pretty simple. You should also avoid closing and reopening the connection between statements (which won’t be possible in a useful transaction anyway). You only need to open the connection on the first call, and close after the last. Last, you should put the last close before the Redirect because Redirect(string) will abort the thread.

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

Sidebar

Related Questions

I have a Survey model and each survey has_many questions and each question belongs_to
I've got a mySQL database of survey responses. Each one has a userID, a
Each of my clients can have many todo items and every todo item has
Each page of my site has 10 (almost) identical divs, varying only in the
I'm working with survey data where each survey has 1 or 2 rows of
Each time a python file is imported that contains a large quantity of static
Each year at Thanksgiving, my family has drawn names out of a hat to
Each of these variables has an integer value. But this syntax is not valid
Each time my webpage is loaded it runs a routine in the page_load event
Each book can have many authors. And each author can author many books. class

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.