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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:33:04+00:00 2026-06-03T08:33:04+00:00

I am using winforms application with a datagridview. Problem :Trying to save the edited

  • 0

I am using winforms application with a datagridview.
Problem :Trying to save the edited data in the database
Code:

     private void FillData(string selectCommand)
        {
            SQLiteConnection conn = new SQLiteConnection(connString);
            dataGridView1.AutoGenerateColumns = true;
            string selectCommand = "select * from Table1";
            da = new SQLiteDataAdapter(selectCommand, connString);
            conn.Open();
            ds = new DataSet();
            SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(da);
            da.Fill(ds,"Design1");
            dataGridView1.DataSource = ds.Tables[0] ;
            dataGridView1.DataMember = "Design1";
      }
 private void btnSave_Click(object sender, EventArgs e)
        {
            SQLiteConnection conn = new SQLiteConnection(connString);
            try
            {

                dataGridView1.EndEdit();

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ds.Tables[0].Rows[i].AcceptChanges();
                }

                da.Update(ds.Tables[0]);


            }
            catch (Exception ex)
            {

                throw ex;
            }

        }

Not sure if this is an issue with Sqlite.
There are no errors, except it does not update in the DB. Once I stop the application and reload it, edits are saved in DB.

Thank you
Sun

  • 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-03T08:33:05+00:00Added an answer on June 3, 2026 at 8:33 am

    I think you should reverse the order of AcceptChanges and Update lines

                dataGridView1.EndEdit(); 
                da.Update(ds.Tables[0]); 
                // Just accept on the table, no need to do row by row
                ds.Tables[0].AcceptChanges();
    

    See the Remarks here for a reference

    Let me say also, keeping all that vars around is not a good practice.
    They could introduce side effects and bugs difficult to track.
    In special mode, the connection should be disposed as fast as possible, encapsulanting in a using statement. (Provided that you explicity request the connection pooling feature -> "Pooling=True;Max Pool Size=100;")

    For example:

         private void SaveData(DataGridView dgv, string selectCommand)  
         {  
            using(SQLiteConnection conn = new SQLiteConnection(connString))
            {
                conn.Open(); 
                SQLiteDataAdapter da = new SQLiteDataAdapter(selectCommand, connString); 
                SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(da); 
                DataTable dt = dgv.DataSource as DataTable;
                da.Update(dt);
                dt.AcceptChanges();
            }
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to populate a DataGridView on my WinForms application ( dgvOrderSizes ) using
My team working in a project using Winforms application(c#) & MSSQL 2005 as database.
We are developing a multilingual Winforms application using visual studio 2008. I am trying
I am trying to make a multiple page application using winforms. I decied to
I have a problem with binding data using BindingSource, typed dataset and DataGridView. My
I have a database winforms application using SQLite written in C#. I'm attempting to
I am using Winforms for my application & SQL Server as database. I want
im attempting to export the datagridview to excel(.xls) in a winforms application using visual
I have a WinForms application which is using Entity Framework to query a database.
I'm using a DataGridView in my WinForms application. My main objective is to make

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.