Saturday 29 September 2012

The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

"The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again." OleDbException was unhandled.

Actually Here I Want To Save The DataGridview Data In The Database. In The Database One Column That Is First Column Has Primary Key, Which Does Not Allow Duplicate Values. 

I Have Saved Some Data Through The Datagridview To The Database.

I Had Saved Some Data In To The DataBase Through THe DataGridView...And When I Reload(Re-Run)  The Form Then The Data Is Reloaded At Form Load Time..Due To The OleDb Connection The Data Is Stored In The DataSet, So When We Load The Form The Previous Stored Data Will Also Display In The DataGridView. As Shown Below  I Am Showing That THe DataGridView Data Previously Stored And Also The New Data That I Had Given Now.  When I Click On Save Button..Due To The Already Stored  Data In The Database Again It Is Trying To Save The Existing Data WIth The New Data.

Due To That Database Does Not Allow Duplicate Values In To The Database. It Shows An Error That Is: OleDbException was unhandled."The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."

So To Overcome This Exception We Have to Clear The DataTable At Form Load. So We Can Enter New Data. And It Does Not Show THe Old Data or Already Existing Data. After Clearing THe DataTable It Looks As Below:
Now We Can Enter New Data In The Database And Click Save Button. Then The New Data Is Stored In THe Database Through The DataGridView. And Runs Successfully .

No comments:

Post a Comment

Note: only a member of this blog may post a comment.