Results 1 to 3 of 3

Thread: help with constraint error

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width