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. Image for the cookie policy date

Reg: Databound grid control exception

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

4 Replies

ST stanleyj Syncfusion Team 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


AS Anna Srinivasan 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


AS Anna Srinivasan January 20, 2006 04:04 AM UTC

Solution pls


AD Administrator Syncfusion Team 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.

Forum_20Jan_39774_validating.zip

Loader.
Live Chat Icon For mobile
Up arrow icon