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

  • Home
  • SEARCH
  • 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 7813665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:57:02+00:00 2026-06-02T04:57:02+00:00

I have a four column table in a SQL Server database. The info for

  • 0

I have a four column table in a SQL Server database. The info for the first three columns is supplied by another source. Column 4 is set to null by default.

I then have a win form with a datatable that populates with the information from the SQL Server database using the following code:

public DataTable populateFormList()
{
    SqlConnection con = new SqlConnection(Properties.Settings.Default.sqlConnectionString);
    SqlCommand cmd = new SqlCommand("SELECT * FROM of_formlist_raw", con);
    con.Open();

    SqlDataReader reader = cmd.ExecuteReader();

    DataTable dt = new DataTable();
    dt.Load(reader);

    return dt;
}

datagridview2.DataSource = populateFormList();
datagridview2.Refresh();

Now that works fine in obtaining my data.

The user can then make changes to the null values in column 4.

How can I easily write these changes from the datatable back into the SQL Server table?

In other words, once the on screen datatable has additional values, how can I then store the updated information back in the SQL Server database from which it was originally obtained from?

Thanks.

  • 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-02T04:57:05+00:00Added an answer on June 2, 2026 at 4:57 am

    Try something like this and just pass (DataTable)datagridview2.DataSource as the data table:

    private static void BulkInsertToSQL(DataTable dt, string tableName)
            {
    
                    using (SqlConnection con = new SqlConnection(_DB))
                    {
                        SqlBulkCopy sbc = new SqlBulkCopy(con);
                        sbc.DestinationTableName = tableName;
    
                        //if your DB col names don’t match your data table column names 100%
                        //then relate the source data table column names with the destination DB cols
                        sbc.ColumnMappings.Add("DBAttributeName1", "DTColumnName1");
                        sbc.ColumnMappings.Add("DBAttributeName2", "DTColumnName2");
                        sbc.ColumnMappings.Add("DBAttributeName3", "DTColumnName3");
                        sbc.ColumnMappings.Add("DBAttributeName4", "DTColumnName4");
    
                        con.Open();
    
                        sbc.WriteToServer(dt);
                        con.Close();
                    }
    
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using sql server 2000 .I have a table with four columns ie.
I have two SQL Server tables. One table has four nvarchar(50) nullable columns and
Using SQL Server 2005 I have a table with the following columns id name
I have a database table has four columns called Courses(CourseID,CourseName,CreditHours,LabSession) , and I wanna
In my My-SQL database, I have an article table (with columns article_id, article_name &
I have a database column in a SQL Server 2008 database that contains VARCHAR
I have a table with one column and four rows. Each tr has a
I have a table with four Columns: Col1, Col2, Col3, and Col4. Col1, Col2,
I have a fairly static (InnoDB) table T with four columns: A , B
I have a secondhand sale car database and four tables with relationships. Same column

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.