|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem with auto generated update commandHere is my particular situation, I drag table BusinessDev from the server explorer onto a dataset. VS2005 automatically creates the data table and table adapter with the select, insert, update and delete command. In SQL Server, table BusinessDev have an trigger on it for after update. In that trigger I update the field name DateModified. I check with UPDATE(DateModified) to only update the field when the table is not updated by the trigger. For this to work properly when I update the database with the table adapter I must not pass the DateModified field. I go in the dataset click on the table adapter, then in the properties window I select the update command and click on the button to show the query builder for the command. In the table's fields list I uncheck the field DateModified and click ok. Then what happen is very strange the code generated for the command is changed and the lines that set the @IsNull_ParameterName parameters value to either 1 or 0 are removed and the update command fails with parameter not supplied error. Here is a sample of the original code from the update command before I remove the field DateModified through the IDE: if ((Original_ScalaCustomerID == null)) { this.Adapter.UpdateCommand.Parameters[12].Value = ((object)(1)); this.Adapter.UpdateCommand.Parameters[13].Value = System.DBNull.Value; } else { this.Adapter.UpdateCommand.Parameters[12].Value = ((object)(0)); this.Adapter.UpdateCommand.Parameters[13].Value = ((string)(Original_ScalaCustomerID)); } And here is the same code sample after I removed the field DateModified through the IDE: if ((IsNull_ScalaCustomerID == null)) { throw new System.ArgumentNullException("IsNull_ScalaCustomerID"); } else { this.Adapter.UpdateCommand.Parameters[12].Value = ((string)(IsNull_ScalaCustomerID)); } if ((Original_ScalaCustomerID == null)) { this.Adapter.UpdateCommand.Parameters[13].Value = System.DBNull.Value; } else { this.Adapter.UpdateCommand.Parameters[13].Value = ((string)(Original_ScalaCustomerID)); } Am I missing something here or is this a problem with the IDE? I have tried to change the code manually but on recompile my changes are replaced with the generated code. I have work around this problem by removing the DateModified field from the select statement and have the IDE recreate the insert, update and delete command from the new select statement. Then once that is done I add the DateModified field back in the select statement and answer no when I'm ask if I want to update the insert, update and delete statement to reflect the changes made to the select statement. The only problem with this is when I update the database the DateModified field is not selected back to update the dataset. If I modify the select part of the update statement to select the DateModified field I get the same problem as before. Thank you for your help. Michel |
|||||||||||||||||||||||