Here's one fix
Posted by: Lou Arnold
Date: September 21, 2006 12:36PM

First an observation re my previous post: The Insert, Update and Delete Commands in a CommandBuilder object don't get built until the DataAdapter's Update method is called.

But the insert and update commands may be the wrong focus altogether. The problem occurs when you declare EndCurrentEdit for a field (see the code below). The exception about the NULL ID value occurs (in System.Data.dll) as that statement executes. It does not occur at the Update call.

One solution that works is the single line that is commented out below. Setting the textbox tbCpyID to "0" forces MySql to perform its auto increment. It doesn't take another call to MySql to get the last ID, and there is no MySql specific method. And there is no need to change any of the SQL commands for the Data Adapter or the CommandBuilder. If anyone can come up with disadvantages to this I would be pleased to hear them. It was too simple to be robust.

------------
private: System::Void tbCpyName_Leave(System::Object^ sender, System::EventArgs^ e) {
//Note that losing focus happens when the mouse is clicked in another control.
//This code is executed when the Company Name textbox loses focus.
//This means that the textbox contents may have been changed.
//So we declare the end of editing and Update the dataset.
//Following line is commented out to generate the null not allowed exception
//tbCpyID->Text="0"; //Set the key value to zero so MySql will handle the autoincrement this->tbCpyName->DataBindings["Text"]->BindingManagerBase->EndCurrentEdit();
int bb; //test
bb=pCpyDA->Update(dataSet1,"tblCompany"); //bb is the number of rows updated
}
---------------



Edited 2 time(s). Last edit at 09/21/2006 01:51PM by Lou Arnold .

Options: ReplyQuote


Subject
Written By
Posted
September 21, 2006 09:35AM
September 21, 2006 11:44AM
September 26, 2006 01:24AM
Here's one fix
September 21, 2006 12:36PM
September 27, 2006 07:40PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.