Results 1 to 9 of 9

Thread: How to create relationship between tables vb.net (localdB)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    How to create relationship between tables vb.net (localdB)

    I created a database table Stock/Products/Sales

    Stock table Products Sales
    ----------------- ----------------------- ----------
    StockID ProductID SalesId
    Category: Product-category Product Type
    Product : Product Qty
    Date: Quantity Price
    Quantity: Price
    Price:
    ------------------ ------------------------ ------------------
    .
    Can anyone explain a little how to bind tables with each other example Products getdetails from Stock,Sales getdetails from Product.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How to create relationship between tables vb.net (localdB)

    It's called a foreign key and one (not sure if it's the only way but it's the only way I know) to add one to a local SQL Server data file is to open the child table in the designer, right-click on the Foreign Keys node in the righthand pane, select Add New Foreign Key and then edit the SQL code for the table appropriately. For instance, I just created a Parent table like this:
    sql Code:
    1. CREATE TABLE [dbo].[Parent]
    2. (
    3.     [ParentId] INT NOT NULL PRIMARY KEY,
    4.     [ParentName] NVARCHAR(50) NOT NULL
    5. )
    and then a Child table with a foreign key like this:
    sql Code:
    1. CREATE TABLE [dbo].[Child]
    2. (
    3.     [ChildId] INT NOT NULL PRIMARY KEY,
    4.     [ParentId] INT NOT NULL,
    5.     [ChildName] NVARCHAR(50) NOT NULL,
    6.     CONSTRAINT [FK_Child_Parent] FOREIGN KEY ([ParentId]) REFERENCES [Parent]([ParentId])
    7. )
    Once you add the foreign key to the existent child table, much of the SQL code will be generated for you and you can just change the table and column names as appropriate.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: How to create relationship between tables vb.net (localdB)

    I will try but everytime i bind stockID with prodID, it only show how much records are it doesnt show the record

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: How to create relationship between tables vb.net (localdB)

    I go in Dataset1.xsd = stockTable right click/add relation/ then stockID=prodID(prodTable)

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How to create relationship between tables vb.net (localdB)

    Quote Originally Posted by ali3nn View Post
    I go in Dataset1.xsd = stockTable right click/add relation/ then stockID=prodID(prodTable)
    You shouldn't have to create a relation in your DataSet. It should be created in the database and then it will be created automatically in your DataSet when that DataSet is generated from the database.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How to create relationship between tables vb.net (localdB)

    Quote Originally Posted by ali3nn View Post
    I will try but everytime i bind stockID with prodID, it only show how much records are it doesnt show the record
    Why would you relate those two columns? Maybe you could provide a proper description of your schema. As you can see, what you put in post #1 is basically unreadable. Perhaps try previewing your posts before submitting.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: How to create relationship between tables vb.net (localdB)

    Name:  123_1.jpg
Views: 430
Size:  26.9 KB
    Here is a image, to make a realtionship i go Dataset1.xsd and click on the table that i want to bind properties add realationship

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How to create relationship between tables vb.net (localdB)

    I didn't ask you how you did it. I asked you why. On the surface, it doesn't seem like those columns are related. That's why I asked you to provide a proper description of your schema, which you have also not done. I'm trying to help but I need relevant information in order to do so. If you aren't prepared to take the time and make the effort to provide a FULL and CLEAR explanation of the problem then I'm not prepared to keep trying to help.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: How to create relationship between tables vb.net (localdB)

    I need dbo.Stock to send informations to dbo.Products.. example when i register a product on stock it must show on the product too ??

    so how to bind these tables ??

Tags for this Thread

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