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.