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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:27:56+00:00 2026-06-03T20:27:56+00:00

I keep getting an InvalidOperationException (Update requires a valid UpdateCommand when passed DataRow collection

  • 0

I keep getting an InvalidOperationException (“Update requires a valid UpdateCommand when passed DataRow collection with modified rows”). I just cant work out what’s wrong with the update command.

Here’s the code I have so far:

    OleDbConnection connection;
    OleDbDataAdapter clientsAdapter new OleDbDataAdapter();
    DataSet myDataSet = new DataSet();

    public void Setup()
    {
        connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Clients.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES"";";
        connection = new OleDbConnection(connectionString);
        connection.Open();


        // SQL
        clientsAdapter.SelectCommand = new OleDbCommand("SELECT * FROM [Clients$]", connection);
        OleDbCommand updateCmd = new OleDbCommand(
            "UPDATE [Clients$] " + 
            "SET " +
                "[Family Name] = ?, " +
                "[Given Name] = ?, " + 
                "Address = ?, " + 
                "[Home Phone] = ?, " + 
                "[Work Phone] = ?, " + 
                "[Mobile Phone] = ?, " + 
                "Email = ?, " + 
                "Status = ?, " + 
                "Comments = ? " + 
            "WHERE " + 
                "[Last Name] = ? AND " + 
                "[First Name] = ?"

        // SET clause
        updateCmd.Parameters.Add("Family Name", OleDbType.Char, 100, "Family Name");
        updateCmd.Parameters.Add("Given Name", OleDbType.Char, 100, "Given Name");
        updateCmd.Parameters.Add("Address", OleDbType.Char, 100, "Address");
        updateCmd.Parameters.Add("Home Phone", OleDbType.Double, 100, "Home Phone");
        updateCmd.Parameters.Add("Work Phone", OleDbType.Char, 100, "Work Phone");
        updateCmd.Parameters.Add("Mobile Phone", OleDbType.Char, 100, "Mobile Phone");
        updateCmd.Parameters.Add("Email", OleDbType.Char, 100, "Email");
        updateCmd.Parameters.Add("Status", OleDbType.Char, 100, "Status");
        updateCmd.Parameters.Add("Comments", OleDbType.Char, 100, "Comments");

        // WHERE clause
        OleDbParameter fName = updateCmd.Parameters.Add("Old Family Name", OleDbType.Char, 100, "Family Name");
        fName.SourceVersion = DataRowVersion.Original;
        OleDbParameter lName = updateCmd.Parameters.Add("Old Given Name", OleDbType.Char, 100, "Given Name");
        lName.SourceVersion = DataRowVersion.Original;

        clientsAdapter.InsertCommand = updateCmd;

        // create table and fill
        DataTable clients = new DataTable("Clients");
        clientsAdapter.Fill(clients);
        myDataSet.Tables.Add(clients);

        connection.Close();
    }

    public void UpdateDb()
    {
        connection.Open();
        clientsAdapter.Update(myDataSet, "Clients");  // errer occurs here
        connection.Close();
    }

Although there are several simple examples on google, I have not been able to work out a solution.

  • 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-03T20:27:58+00:00Added an answer on June 3, 2026 at 8:27 pm

    You haven’t set the UpdateCommand property of clientsAdapter.

    You’ve created a OleDbCommand called “updateCmd”, but then you’ve set the InsertCommand property to it:

    clientsAdapter.InsertCommand = updateCmd;

    I suspect you wanted:

    clientsAdapter.UpdateCommand = updateCmd;

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

Sidebar

Related Questions

I keep getting a InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's
This has been driving me nuts. I keep getting the following exception System.InvalidOperationException: The
I keep getting this statement Invalid use of group function for this query mysql_query(UPDATE
I have a question: I keep getting an InvalidOperationException: Element is already child of
I keep getting the following InvalidOperationException : The relationship between the two objects cannot
I keep getting an error saying my value is not positioned on a valid
Keep getting this error after inserting a subdatasheet into a query and trying to
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition
I keep getting this : DeprecationWarning: integer argument expected, got float How do I
I keep getting a 'List does not exist' error whenever I try and use

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.