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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:51:10+00:00 2026-05-28T14:51:10+00:00

When I select the in the gridview using checkbox, I want it to insert

  • 0

When I select the in the gridview using checkbox, I want it to insert the data into the database, but it is not adding it. My code is below, please see where I am going wrong.

public partial class HomeTeamCheckList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LiveGameReporting Window
        SubmitLineUp.Attributes.Add("onclick", "PassValues();");

        SubmitLineUp.Text = "Submit " + Session["HomeTeam"] + "'s Line Up";
    }

    protected void SubmitLineUp_Click(object sender, EventArgs e)
    {
        String GameID = string.Empty;
        String Name = string.Empty;
        String Number = string.Empty;

        int GKGVCount = GoalKeeperGridView.Rows.Count;


        foreach (GridViewRow gkrow in GoalKeeperGridView.Rows)
        {
            GameID = (String)Session["GameID"];
            Number = gkrow.Cells[0].Text;
            Name = gkrow.Cells[1].Text;

             SqlConnection connection = new SqlConnection(("Data Source=ROBEL-HP;Initial Catalog=RocoSportsDB;Integrated Security=True"));

            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = connection;
                cmd.CommandText = @"INSERT INTO HTLineUp (GameID, HomeTeamLineUpNo, HomeTeamLineUpName) VALUES (@GameID,@Number,@Name)";

                cmd.Parameters.AddWithValue("@GameID", GameID);
                cmd.Parameters.AddWithValue("@Number", Number);
                cmd.Parameters.AddWithValue("@Name", Name);

                cmd.ExecuteNonQuery();
            }
        }
    }
}
  • 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-28T14:51:11+00:00Added an answer on May 28, 2026 at 2:51 pm

    Two thoughts:

    • Use a try-catch to see if you’re getting any SQL errors.
    • Check the return value of the cmd.ExecuteNonQuery(); to see if any rows were actually affected / inserted.

    Like this:

     SqlConnection connection = new SqlConnection(("Data Source=ROBEL-HP;Initial Catalog=RocoSportsDB;Integrated Security=True")); 
     try
     { 
        SqlCommand cmd = new SqlCommand(); 
        cmd.Connection = connection; 
        cmd.CommandText = @"INSERT INTO HTLineUp (GameID, HomeTeamLineUpNo, HomeTeamLineUpName) VALUES (@GameID,@Number,@Name)"; 
    
        cmd.Parameters.AddWithValue("@GameID", GameID); 
        cmd.Parameters.AddWithValue("@Number", Number); 
        cmd.Parameters.AddWithValue("@Name", Name); 
    
        // use a debugger to see if any rows were actually affected / inserted
        int rowsAffected = cmd.ExecuteNonQuery(); 
     } 
     catch(SQLException error)
     {
         // Use a debugger to see if you are getting an error on execution
         string errorText = error.message;
     }
    

    Your query string looks ok, so it could be a permissions error. But the steps above will help you track it down.

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

Sidebar

Related Questions

I am using a gridview to select, delete and update data in database. I
I'm using checkbox to select the rows in the gridview. How do I insert
How do I put data into a gridview using programming code? I need an
I am using vb.net code in which I am having a gridview control. Please
I am using checkbox in the gridview header to select all records in the
I've been using some code very similar to the following to populate a gridview
Using C# & ASP.Net In my webpage am using gridview Code. In a GridView
How can I populate a GridView using a connection to an Access Database? So
I have a list view that is displaying data using the gridview. This list
I've a Gridview control using an ODS(ObjectDataSource) to fetch data. For the best performance

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.