We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Reg: Databound grid control exception

Thread ID:





39774 Jan 18,2006 09:04 AM UTC Jan 20,2006 12:11 PM UTC WinForms 4
Tags: GridControl
Anna Srinivasan
Asked On January 18, 2006 09:04 AM UTC

Hi, I am getting following error while inserting new row in grid data bound control. System.Data.ConstraintException: Column ''ASSET_ID, HISTORY_DATE'' is constrained to be unique. Value ''18229614, 01/16/2006 12:00:00 AM'' is already present. at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge) at System.Data.DataRow.SetNewRecord(Int32 record) at System.Data.DataRow.EndEdit() at System.Data.DataRowView.EndEdit() at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.EndEdit() at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.EndEdit() System.Data.ConstraintException: Column ''ASSET_ID, HISTORY_DATE'' is constrained to be unique. Value ''18229614, 01/16/2006 12:00:00 AM'' is already present. at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.EndEdit() at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.OnCurrentCellAcceptedChanges(CancelEventArgs e) at Syncfusion.Windows.Forms.Grid.GridControlBase.RaiseCurrentCellAcceptedChanges() at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) catched at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.EndEdit() in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) in :line 0 How do i catch this event..? Thanks, Anna

stanleyj [Syncfusion]
Replied On January 18, 2006 10:26 AM UTC

Hi Anna, This ConstraintException has to be handled. As a DataRow is inserted with a duplicate PrimaryKey System.Data throws this exception. Grid does not raise any events for this. Regards, Stanley

Anna Srinivasan
Replied On January 18, 2006 11:51 AM UTC

Hi, Yes I got the problem. I will explain what exactly happening in my app. I have databound grid , I am assinging datatable to the grid(All the rows and columns are editable). If user goes and change the date one which already present in the datable, I am getting this exception. This senario how do i handle this problem..? I don''t want user to see the exception on the debug window. According to my requirement, How do i face this. Thanks, Anna

Anna Srinivasan
Replied On January 20, 2006 04:04 AM UTC

Solution pls

Administrator [Syncfusion]
Replied On January 20, 2006 12:11 PM UTC

Hi Anna, In general, the PrimaryKey Column does not accept any duplicate and null values..it throws the exception if you change the cell value to the already present cell value. Will that be ok, for you to programmatically check for repeated entries to avoid the exception in the output window? If so then the validation can be performed in the CurrentCellValidating Event Handler. Please take a look at the sample for more details. string oldValue, newValue,cValue; private void gridDataBoundGrid1_CurrentCellValidating(object sender, System.ComponentModel.CancelEventArgs e) { GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; if(cc.Renderer.StyleInfo.CellValueType == typeof(DateTime)) { oldValue = Convert.ToString(this.gridDataBoundGrid1[cc.RowIndex,cc.ColIndex].CellValue); newValue = cc.Renderer.ControlText + " 12:00:00 AM"; for(int i =1; i < this.gridDataBoundGrid1.Model.RowCount; i++) { cValue = this.gridDataBoundGrid1[i,cc.ColIndex].CellValue.ToString() ; if(newValue == cValue) if( oldValue == string.Empty) e.Cancel = true; else cc.Renderer.ControlText = oldValue; break; } } } Let us know if you need any assistance, Regards, Madhan.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon