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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:28:27+00:00 2026-06-05T06:28:27+00:00

I am creating a C# program where I can add data from the system

  • 0

I am creating a C# program where I can add data from the system and save to the the database. I am using SQL Server 2008 R2. I have a data grid view which has 2 tables, name and address. What I want to do is after inputting the needed information I want it to be saved in my database after I click the save button.

This is the screenshot of my data grid view:

enter image description here

I have a code in saving data from a textbox into my database. But I used textbox on that and I don’t have any idea on how to do the same process(saving data into my database) using data grid view instead of textbox. Please help. Thanks.

This is the code I used in saving data from a textbox to my database.:

string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
try
{
    using (SqlConnection connect = new SqlConnection(connectionString))
    {
        SqlCommand command = new SqlCommand();
        command.Connection = connect;
        command.CommandText = "insert into customer(name, address) values(@name, @address)";
        command.Parameters.Add(new SqlParameter("@name", SqlDbType.VarChar));
        command.Parameters.Add(new SqlParameter("@address", SqlDbType.VarChar));
        command.Parameters["@name"].Value = name.Text.ToLower();
        command.Parameters["@address"].Value = address.Text.ToLower();
        connect.Open();
    }
}
  • 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-05T06:28:28+00:00Added an answer on June 5, 2026 at 6:28 am

    You need to iterate the DataGridView.Rows collection (I assume the DataGridView is unbounded).

    using (SqlConnection connect = new SqlConnection(connectionString))
        {
          using(SqlCommand command = new SqlCommand())
           {
            command.Connection = connect;
            command.CommandText = "insert into customer(name, address) values(@name, @address)";
    
            command.Parameters.Add(new SqlParameter("@name", SqlDbType.VarChar));
            command.Parameters.Add(new SqlParameter("@address", SqlDbType.VarChar));
            connect.Open();
            foreach (DataGridViewRow row in dataGridView1.Rows)
             {
              if(!row.IsNewRow)
               {
                 command.Parameters["@name"].Value = row.Cells[0].Value;
                 command.Parameters["@address"].Value = row.Cells[1].Value;
                 command.ExecuteNonQuery();
               }
             }
          }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing SQL Server database whose structure I can't really change, although
I have a program that is responsible for reading data, formatting it and creating
I need help creating a script or program that can add users to my
I am creating a program to see if I can run a byte array
im creating a program that will compile java files, at the moment i have
I'm creating a program that authenticates from a before it runs. I also want
I use the following program for creating JTable using java class. If I get
I am creating a program that encrypts/hashs messages I have a list that contains
When creating system services which must have a high reliability, I often end up
I'm creating a program in SWT. I have a first Shell that has on

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.