Link to home
Start Free TrialLog in
Avatar of aj85
aj85

asked on

C# Error - Add Failed

I am connecting a C# DB application to a SQL Server DB, and when I run the application, it will open and run correctly.  In the application I am inserting, updating, and editing data.  When I add the first record, it will save correctly into the DB, however when I try to add another record, I immediately get the attached error message, and cannot add any additional information.  I am not sure what is occurring as the application connects with the DB correctly, but it seems that either the DB gets locked after the first record, or something is happening with C# that is preventing this.  I have tried, dropping the DB, and recreating it, which did not work, and I have tried creating a different DB with the same schema, but I get the same results.  Not sure where to turn next, so any advice would be appreciated.

Regards,
aj85
C-_Error.PNG
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

It would help to see the code that you are using. The error doesn't seem to be a SQL error.
code pls.
Avatar of aj85
aj85

ASKER

Understood.  Attached is the code that is executed when the "Save" button is clicked to add a new record.  Again, works with the first record, but does not on the second.

Regards,
aj85
Save_Button_Code.txt
Where in that code are you updating the DB?
SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aj85

ASKER

Fernando,

I updated the previous upload to include the code that handles the update to the DB.  

Daniel,

Thanks for the advise, I will add what you have recommended, and get back to you shortly.

Regards,

aj85
Avatar of aj85

ASKER

Hello Daniel,

The example code that you provided, yielded the same error result.  Just an FYI.  I am beginning to think there is an issue with Krypton component set that I am using.  

Regards,

aj85
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aj85

ASKER

Hello Pawan,

Thanks for the code, however I tried it and received a "Update Unsuccessful: ObjectNotFound" after I added the first record.

Regards,
aj85
See error is coming from Edit section-- ("Update unsuccessful", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);

You are adding  records and your controls is going in below section--

else if (_editMode == EditMode.Edit)

Open in new window


I think it is due to this - UpdateControlsForCurrentEditMode();
Once the code is added, why you are setting this for editing.  Ideally the user should again click on edit button to make an edit in there.

Hope it helps !!
Avatar of aj85

ASKER

Hello Pawan,

Thanks for the quick response, and I will get back to you shortly after I try this again.  However, I am not sure I am understanding clearly why I would need to put the user in Edit mode after they just added a single record.  They are not editing the exiting record, but adding new information.  Perhaps this is just how the Krypton components function, as I have not used them in the past.

Regards,
aj85
Avatar of aj85

ASKER

Thank you all.  It took a combination of your suggestions to solve the issues.