|
-
May 24th, 2007, 10:25 AM
#1
Thread Starter
PowerPoster
help with constraint error
i dont know how to go about resolving this problem. such a toughy and my brains are almost dead!
Basically, if we add a "criteria" into a gridview, then we delete a row of critieria and add a new one, this is the exception I get:
Code:
Column 'ReportCriteriaId, ReportId' is constrained to be unique. Value '4, 3' is already present.
the 4, 3 varies.
This is throwing up from the dataset tableadapter code that this person created in VS.NET
any ideas how to go about resolving this issue?
the code when removing the criteria is this (in the rowDeleting event of the gridview)
Code:
protected void gvReportSpec_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
{
//some stuff here to get hold of the row to delete in the tableadapter/datatable
oReportCriteriaRow.Delete();
this.BindCriteria();
if (this.gvReportSpec.Rows.Count > 0)
{
DropDownList ddList = this.gvReportSpec.FindControl("ControlName");
if (ddList != null)
{
ddList.Items.Clear();
}
}
}
basically when deleting, it will find the row to delete in the tableset/datatable and do a "Delete" on it. Then it will find the next row in the gridview and remove the items in the drop down list.
But then when we add a crieteria, (another row) it will throw the exception as above. The code for adding a criteria:
Code:
this.CurrentReportSet.ReportCriteria.AddReportCriteriaRow("", CurrentReportSet.ReportCriteriaType.FindByReportCriteriaTypeId(ReportCriteriaId_IsNotNull), ")", "AND", "ColumnFieldName", "TableName", CurrentReport, CurrentReportSet.ReportCriteria.Rows.Count + 1);
no idea if this helps but I'm still learning my way through the code given!
any help is appreciated on how to overcome this contraints problem when removing a row of data from the gridview and adding a new one
-
May 24th, 2007, 11:04 AM
#2
Thread Starter
PowerPoster
Re: help with constraint error
i found out it - had to renumber the reportCriteriaID Field since it was not an IDENT in the table 
next problem is the nullRefException now
Code:
' Validate the proposed edit
If (this.ValidateCriteriaValues(stCriteriaValue, oReportCriteriaRow.ReportableAttributeRowParent.DataTypeId, stErrorMessage))
{
//DoStuff
}
the "ReportableAttributeRowParent" property is null since I wouldve deleted it. any ideas how to go around this frustrating problem?
so now it deletes the row we tell it to on the gridview and renumbers the ID for the DataTable.....but then when we add a new criteria....it throws up the nullRefException
-
May 24th, 2007, 07:05 PM
#3
Re: help with constraint error
Is it that line specifically that throws the exception or something inside the ValidateCriteriaValues method? If it's that line then it can't be too hard to find the null reference. NullReferenceExceptions occur when you try to access a member via a reference that is null. There are only three dots in that line of code so there are only three possibilities for the null reference. I very much doubt that it's 'this', so that only leaves two possibilities.
The rules for diagnosing a NullReferenceException are very simple:
1. Test each reference on the offending line to determine which is null.
2. Work backwards through the call stack until you find the place that you expected a value to be assigned to that reference.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|