Results 1 to 9 of 9

Thread: [RESOLVED] [2005] Relating Tables in a Dataset

  1. #1

    Thread Starter
    Junior Member vb3119's Avatar
    Join Date
    Jun 2007
    Posts
    29

    Resolved [RESOLVED] [2005] Relating Tables in a Dataset

    I'm trying to create a dataset with multiple tables that are related by an ID field.

    In the main table I'm setting auto increment to the first column and calling that column 'custID' , but when I create another table and try to put a 'custID' field in I get an error saying I can't have the same column name in two different tables.

    how do I connect the two tables together so they both contain the 'custID' number?

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Relating Tables in a Dataset

    You can generate relations in your DataSet by just dragging fields from one table to another directly in the designer.

  3. #3

    Thread Starter
    Junior Member vb3119's Avatar
    Join Date
    Jun 2007
    Posts
    29

    Re: [2005] Relating Tables in a Dataset

    I'm still a little confused.

    Wouldn't a normal relational database have a detail table with 'CustID', 'name', 'address', ... All the basic customer information.

    And then, say, an order table with 'CustID', 'item', 'Qty', '$Amount',... All the order information for each order.

    Why won't VB let me create two tables with a 'CustID' field?

    When I try to create a second table in a Dataset with the ID field it gives me an error saying:
    "Identifier 'CustID ' is not valid."

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [2005] Relating Tables in a Dataset

    Show your code please... It's very hard to debug without seeing what's going.

  5. #5

    Thread Starter
    Junior Member vb3119's Avatar
    Join Date
    Jun 2007
    Posts
    29

    Re: [2005] Relating Tables in a Dataset

    There is no code to show.

    I double clicked on dataset to add to the form. Then I go into the dataset's properties and go into the Tables collection, add a first table with fields. Then I add a second table and try to call the first field the same name as the first field in the first table and I get the error.

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [2005] Relating Tables in a Dataset

    Quote Originally Posted by vb3119
    There is no code to show.

    I double clicked on dataset to add to the form. Then I go into the dataset's properties and go into the Tables collection, add a first table with fields. Then I add a second table and try to call the first field the same name as the first field in the first table and I get the error.
    I've just tried to replicate the error by doing the same steps as you described but everything was fine... No error whatsoever...

  7. #7

    Thread Starter
    Junior Member vb3119's Avatar
    Join Date
    Jun 2007
    Posts
    29

    Re: [2005] Relating Tables in a Dataset

    That's strange. Here's what I'm doing step by step.
    (I'm running this in VB2005 express)

    Open new windows app
    Double click on DataSet (select untyped dataset)
    In DataSet1 properties:
    Click on 'Tables' collection
    click add (creates table1)
    in table1 I click on Columns collection
    add column,
    change the '(name)' field under the 'design' section (not the 'Column name') to 'CustID'
    add a second column 'desc'

    Now,

    I get out of table1 and add another table, table2
    in table2 I add one column.
    Change the (name) field under the 'design' section to 'CustID'

    I then get an error:

  8. #8
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Relating Tables in a Dataset

    Aha! That's like trying to name two different TextBoxes both "TextBox1." You can't do it.

    Add one table and add one column and don't change anything. Add another table and column and you'll see the second column in Table2 is called DataColumn2 even though it is in a different table.

    Change the names and just name the Columns different things.

  9. #9

    Thread Starter
    Junior Member vb3119's Avatar
    Join Date
    Jun 2007
    Posts
    29

    Re: [2005] Relating Tables in a Dataset

    Ahh!!

    That was the problem. Thanks.

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