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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:56:26+00:00 2026-05-23T15:56:26+00:00

On form close I call update but I got error message: update requires InsertCommand

  • 0

On form close I call update but I got error message: update requires InsertCommand whereas I inspired from this tut http://www.switchonthecode.com/tutorials/csharp-tutorial-binding-a-datagridview-to-a-database

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace datatablemsaccess
{
    partial class Form1
    {
        OleDbDataAdapter dataAdapter;

        private string getSQL() {
            string sql = "SELECT * from tPerson";
            return sql;
        }

        private string getConnectionString() {

            string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"App_Data\person.mdb";
            return connectionString;
        }

        private DataTable getDataTable(string sql)
        {
            DataTable dataTable;

            string connectionString = getConnectionString();

            using (dataAdapter = new OleDbDataAdapter(sql, connectionString))
            {
                dataTable = new DataTable();
                dataAdapter.Fill(dataTable);
            }

            return dataTable;
        }
    }
}



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;


namespace datatablemsaccess
{
    public partial class Form1 : Form
    {
        BindingSource bindingSource;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string sql = getSQL();

            bindingSource = new BindingSource();

            bindingSource.DataSource = getDataTable(sql);
            dataGridView1.DataSource = bindingSource;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            dataAdapter.Update((DataTable)bindingSource.DataSource);
        }
    }
}
  • 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-23T15:56:27+00:00Added an answer on May 23, 2026 at 3:56 pm

    You need to define an InsertCommand.

    See Update requires a valid InsertCommand when passed DataRow collection with new rows

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

Sidebar

Related Questions

I want that the form will not close by doing Alt + F4 but
I am using this function to close existing form and open a new form.
I have a need to close a parent form from within child form from
Is it safe to call close on a form and then call close again
I have a contactbook, and a form close to it... For the form, one
When a user clicks on the little red x a.k.a. the form close button
The background: My form has a TWebBrowser. I want to close the form with
Is it possible to close an InfoPath form programmatically? I know that it can
I want to close a System.Windows.Forms.Form if the user clicks anywhere outside it. I've
When designing a form I have the option of putting a close button at

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.