none
problem updating datagrid RRS feed

  • Question

  •  

    Hi,

    by using the following code:

    /*

    private: System::Void button2_Click(System:Surprisebject^  sender, System::EventArgs^  e)
       {
        this->Rn_Table1TableAdapter->Update(this->Rn_db1DataSet->Rn_Table1);
       }

    */

     

    I was able to update my Microsoft database table using MS Visual C++

     

    I am no longer able, the following message appears when I attempt to do so:

    /*

    An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll

     

    additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

    */

     

    How do I solve this problem?

    Tuesday, September 25, 2007 12:38 PM

All replies

  • Hi,

     

    Based on your post, when you call DataAdapter.Upate method the exception occurs. This is because you don't specify the DeleteCommand, UpdateCommand and InsertCommand for the DataAdapter object.

     

    When an application calls the Update method, the DataAdapter examines the RowState property, and executes the required INSERT, UPDATE, or DELETE statements iteratively for each row, based on the order of the indexes configured in the DataSet. It should be noted that these statements are not performed as a batch process; each row is updated individually. Please see DataAdapter.Update method about how to properly call this method.

     

    If INSERT, UPDATE, or DELETE statements have not been specified, the Update method generates an exception. However, you can create a SqlCommandBuilder or OleDbCommandBuilder object to automatically generate SQL statements for single-table updates if you set the SelectCommand property of a .NET Framework data provider. Then, any additional SQL statements that you do not set are generated by the CommandBuilder. This generation logic requires key column information to be present in the DataSet. For more information see Automatically Generated Commands.

     

    At last I move this thread from VB language forum to .NET Framework Data Access and Storage forum. Please post your question to the right forum.

     

    Best regards,

    Riquel.

    Thursday, September 27, 2007 7:33 AM