Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
200
SetDataBinding gives Key AlreadyExisits
posted

Usung C Sharp, I have a dataset that has 4 tables in it, I'm populating a table with a sql command, and then setting that table as the datamember programattically as this:

    private void LoadReason() {
      ugReason.DataBindings.Clear();
      string tabname = "";
      if (_audit) {
        tabname = "DXAdditionAuditReasons";
      } else {
        tabname = "DXAdditionReasons";
      }
      DataTable ttable = Requests.SQLGen.ProcessSQLCommand(gobj, "Select * from "+tabname+" where DXAddID = " + _row["ID"], false);
      if (ttable != null) {
        if (_audit) {
          ttable.TableName = "DxAudReason";
          dx.Merge(ttable);
          ugReason.SetDataBinding(dx,"DxAudReason");
          ugReason.DisplayLayout.Bands[0].Columns["ID"].Hidden = true;
          ugReason.DisplayLayout.Bands[0].Columns["DXAddID"].Hidden = true;
          ugReason.DisplayLayout.Bands[0].Columns["ReasonID"].Header.Caption = "Reason";
          LoadValueList();
          ugReason.DisplayLayout.Bands[0].Columns["ReasonID"].ValueList = ugReason.DisplayLayout.ValueLists["Reason"];
          ugReason.Refresh();
        } else {
          ttable.TableName = "DxAddReason";
          dx.Merge(ttable);
          ugReason.SetDataBinding(dx, "DxAddReason");
          ugReason.DisplayLayout.Bands[0].Columns["ID"].Hidden = true;
          ugReason.DisplayLayout.Bands[0].Columns["DXAddID"].Hidden = true;
          ugReason.DisplayLayout.Bands[0].Columns["ReasonID"].Header.Caption = "Reason";
          ugReason.DisplayLayout.Bands[0].Columns["ReasonID"].ValueList = ugReason.DisplayLayout.ValueLists["Reason"];
          ugReason.Refresh();
        }
      }
    }

When I get to the '.SetDataBinding' I get:

Error Message: Key already exists

Parameter name: Key

I'm clearing the databindings already, so there shouldn't be any keys to exist yet, until I set it there in code.

Parents
  • 469350
    Offline posted

    Hi,

    The only reason you would get an error like this is if your data source structure has columns with duplicate keys.

    Note that a child band is also a column. So if you have a data source with a column named "A" and also a child relationship named "A", that would cause an error like the one you are getting here.

    Also, column keys are case insensitive. So if you have a column named "A" and another named "a", that will also cause a problem.

    Another possibility is that the error is occurring elsewhere in your code, like in the InitializeLayout event if you are trying to add an unbound column that has the same key as an existing column. Sometimes these errors can be masked by DotNet and the line of code the error occurs on isn't the one that is highlighted. Try setting the Visual Studio IDE to break on all run-time exceptions so you are certain it's breaking on the correct line.

    And... if none of that helps, see if you can post the call stack of the exception or a small sample project demonstrating the exception and we can look into it further.

Reply Children
No Data