BindingManager Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mitch W

    BindingManager Problem

    Consider the following:

    I have two Access tables: TableA & TableB

    TableA is a list of Names with a ZipID

    TableB is a list of City, States, and Zips with a ZipID as a primary key
    autonumbered

    On a Windows Form I have two text boxes, Name (from TableA) and City (from
    TableB)

    I have the following code:

    OleDbDataAdapte r nameAdapter = new OleDbDataAdapte r("SELECT
    FirstName, ZipID from TableA", connection);
    OleDbDataAdapte r zipAdapter = new OleDbDataAdapte r("SELECT ZipID,
    City from TableB", connection);

    DataSet completeDataSet = new DataSet();

    nameAdapter.Fil l(completeDataS et, "TableA");
    zipAdapter.Fill (completeDataSe t, "TableB");


    DataRelation relation = completeDataSet .Relations.Add( "FullInfo",
    completeDataSet .Tables["TableA"].Columns["ZipID"],
    completeDataSet .Tables["TableB"].Columns["ZipID"],false);

    bManager = this.BindingCon text[completeDataSet , "TableA"];
    tbxParentField1 .DataBindings.A dd("Text", completeDataSet ,
    "TableA.FirstNa me");
    tbxChildField1. DataBindings.Ad d("Text", completeDataSet ,"TableB.City") ;

    I have Next and Previous buttons on the form, with:

    bManager.Positi on += 1; & bManager.Positi on -= 1; respectively

    The form works fine for displaying the FirstName (tbxParentField 1) and
    scrolling through the records, but the City does not move (tbxChildField1 ). I
    just can't figure out what I am missing when binding the TableB.City field so
    that it updates based on the selected FirstName.

    Any help would be greatly appreciated.

    thanks,
    mitch
  • Dave Sexton

    #2
    Re: BindingManager Problem

    Hi Mitch,

    Try to bind tbxChildField1 through FullInfo (the relationship, not TableB):

    tbxChildField1. DataBindings.Ad d("Text", completeDataSet ,
    "TableA.FullInf o.City");


    BTW, you might want to consider using a strong-typed DataSet.

    --
    Dave Sexton

    "Mitch W" <MitchW@discuss ions.microsoft. comwrote in message
    news:C6F6A45D-218A-484D-A665-5B2BB6B74879@mi crosoft.com...
    Consider the following:
    >
    I have two Access tables: TableA & TableB
    >
    TableA is a list of Names with a ZipID
    >
    TableB is a list of City, States, and Zips with a ZipID as a primary key
    autonumbered
    >
    On a Windows Form I have two text boxes, Name (from TableA) and City (from
    TableB)
    >
    I have the following code:
    >
    OleDbDataAdapte r nameAdapter = new OleDbDataAdapte r("SELECT
    FirstName, ZipID from TableA", connection);
    OleDbDataAdapte r zipAdapter = new OleDbDataAdapte r("SELECT ZipID,
    City from TableB", connection);
    >
    DataSet completeDataSet = new DataSet();
    >
    nameAdapter.Fil l(completeDataS et, "TableA");
    zipAdapter.Fill (completeDataSe t, "TableB");
    >
    >
    DataRelation relation = completeDataSet .Relations.Add( "FullInfo",
    completeDataSet .Tables["TableA"].Columns["ZipID"],
    completeDataSet .Tables["TableB"].Columns["ZipID"],false);
    >
    bManager = this.BindingCon text[completeDataSet , "TableA"];
    tbxParentField1 .DataBindings.A dd("Text", completeDataSet ,
    "TableA.FirstNa me");
    tbxChildField1. DataBindings.Ad d("Text",
    completeDataSet ,"TableB.City") ;
    >
    I have Next and Previous buttons on the form, with:
    >
    bManager.Positi on += 1; & bManager.Positi on -= 1; respectively
    >
    The form works fine for displaying the FirstName (tbxParentField 1) and
    scrolling through the records, but the City does not move (tbxChildField1 ).
    I
    just can't figure out what I am missing when binding the TableB.City field
    so
    that it updates based on the selected FirstName.
    >
    Any help would be greatly appreciated.
    >
    thanks,
    mitch

    Comment

    • Mitch W

      #3
      Re: BindingManager Problem

      Hi Dave,

      Thanks for your quick response, it worked like a charm. You gave a BTW, why
      do you recommend a strong-typed DataSet.

      ---mitch

      "Dave Sexton" wrote:
      Hi Mitch,
      >
      Try to bind tbxChildField1 through FullInfo (the relationship, not TableB):
      >
      tbxChildField1. DataBindings.Ad d("Text", completeDataSet ,
      "TableA.FullInf o.City");
      >
      >
      BTW, you might want to consider using a strong-typed DataSet.
      >
      --
      Dave Sexton
      >
      "Mitch W" <MitchW@discuss ions.microsoft. comwrote in message
      news:C6F6A45D-218A-484D-A665-5B2BB6B74879@mi crosoft.com...
      Consider the following:

      I have two Access tables: TableA & TableB

      TableA is a list of Names with a ZipID

      TableB is a list of City, States, and Zips with a ZipID as a primary key
      autonumbered

      On a Windows Form I have two text boxes, Name (from TableA) and City (from
      TableB)

      I have the following code:

      OleDbDataAdapte r nameAdapter = new OleDbDataAdapte r("SELECT
      FirstName, ZipID from TableA", connection);
      OleDbDataAdapte r zipAdapter = new OleDbDataAdapte r("SELECT ZipID,
      City from TableB", connection);

      DataSet completeDataSet = new DataSet();

      nameAdapter.Fil l(completeDataS et, "TableA");
      zipAdapter.Fill (completeDataSe t, "TableB");


      DataRelation relation = completeDataSet .Relations.Add( "FullInfo",
      completeDataSet .Tables["TableA"].Columns["ZipID"],
      completeDataSet .Tables["TableB"].Columns["ZipID"],false);

      bManager = this.BindingCon text[completeDataSet , "TableA"];
      tbxParentField1 .DataBindings.A dd("Text", completeDataSet ,
      "TableA.FirstNa me");
      tbxChildField1. DataBindings.Ad d("Text",
      completeDataSet ,"TableB.City") ;

      I have Next and Previous buttons on the form, with:

      bManager.Positi on += 1; & bManager.Positi on -= 1; respectively

      The form works fine for displaying the FirstName (tbxParentField 1) and
      scrolling through the records, but the City does not move (tbxChildField1 ).
      I
      just can't figure out what I am missing when binding the TableB.City field
      so
      that it updates based on the selected FirstName.

      Any help would be greatly appreciated.

      thanks,
      mitch
      >
      >
      >

      Comment

      • Dave Sexton

        #4
        Re: BindingManager Problem

        Hi Mitch,

        If you like to use designer support you can drag your DataSet into the Form
        from the Toolbox and bind to it using the property grid.

        VS 2005 has increased support for binding.

        Also, strong-typed DataSets reduce the amount of code required to work with
        data, reduce the amount of casting that is required (introducing type-safety)
        and makes code more legible. They also encapsulate the relationships between
        the tables, constraints and binding support every time you need the data on
        multiple forms instead of having to rewrite the same code over and over again.

        --
        Dave Sexton

        "Mitch W" <MitchW@discuss ions.microsoft. comwrote in message
        news:3E0E87F5-2D0A-4638-B1BC-BD1803A68326@mi crosoft.com...
        Hi Dave,
        >
        Thanks for your quick response, it worked like a charm. You gave a BTW, why
        do you recommend a strong-typed DataSet.
        >
        ---mitch
        >
        "Dave Sexton" wrote:
        >
        >Hi Mitch,
        >>
        >Try to bind tbxChildField1 through FullInfo (the relationship, not TableB):
        >>
        >tbxChildField1 .DataBindings.A dd("Text", completeDataSet ,
        >"TableA.FullIn fo.City");
        >>
        >>
        >BTW, you might want to consider using a strong-typed DataSet.
        >>
        >--
        >Dave Sexton
        >>
        >"Mitch W" <MitchW@discuss ions.microsoft. comwrote in message
        >news:C6F6A45 D-218A-484D-A665-5B2BB6B74879@mi crosoft.com...
        Consider the following:
        >
        I have two Access tables: TableA & TableB
        >
        TableA is a list of Names with a ZipID
        >
        TableB is a list of City, States, and Zips with a ZipID as a primary key
        autonumbered
        >
        On a Windows Form I have two text boxes, Name (from TableA) and City
        (from
        TableB)
        >
        I have the following code:
        >
        OleDbDataAdapte r nameAdapter = new OleDbDataAdapte r("SELECT
        FirstName, ZipID from TableA", connection);
        OleDbDataAdapte r zipAdapter = new OleDbDataAdapte r("SELECT ZipID,
        City from TableB", connection);
        >
        DataSet completeDataSet = new DataSet();
        >
        nameAdapter.Fil l(completeDataS et, "TableA");
        zipAdapter.Fill (completeDataSe t, "TableB");
        >
        >
        DataRelation relation = completeDataSet .Relations.Add( "FullInfo",
        completeDataSet .Tables["TableA"].Columns["ZipID"],
        completeDataSet .Tables["TableB"].Columns["ZipID"],false);
        >
        bManager = this.BindingCon text[completeDataSet , "TableA"];
        tbxParentField1 .DataBindings.A dd("Text", completeDataSet ,
        "TableA.FirstNa me");
        tbxChildField1. DataBindings.Ad d("Text",
        completeDataSet ,"TableB.City") ;
        >
        I have Next and Previous buttons on the form, with:
        >
        bManager.Positi on += 1; & bManager.Positi on -= 1; respectively
        >
        The form works fine for displaying the FirstName (tbxParentField 1) and
        scrolling through the records, but the City does not move
        (tbxChildField1 ).
        I
        just can't figure out what I am missing when binding the TableB.City
        field
        so
        that it updates based on the selected FirstName.
        >
        Any help would be greatly appreciated.
        >
        thanks,
        mitch
        >>
        >>
        >>

        Comment

        Working...