-
Apr 7th, 2018, 08:16 PM
#1
Thread Starter
Lively Member
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.
-
Apr 7th, 2018, 09:53 PM
#2
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:
CREATE TABLE [dbo].[Parent] ( [ParentId] INT NOT NULL PRIMARY KEY, [ParentName] NVARCHAR(50) NOT NULL )
and then a Child table with a foreign key like this:
sql Code:
CREATE TABLE [dbo].[Child] ( [ChildId] INT NOT NULL PRIMARY KEY, [ParentId] INT NOT NULL, [ChildName] NVARCHAR(50) NOT NULL, CONSTRAINT [FK_Child_Parent] FOREIGN KEY ([ParentId]) REFERENCES [Parent]([ParentId]) )
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.
-
Apr 8th, 2018, 05:19 AM
#3
Thread Starter
Lively Member
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
-
Apr 8th, 2018, 05:28 AM
#4
Thread Starter
Lively Member
Re: How to create relationship between tables vb.net (localdB)
I go in Dataset1.xsd = stockTable right click/add relation/ then stockID=prodID(prodTable)
-
Apr 8th, 2018, 05:34 AM
#5
Re: How to create relationship between tables vb.net (localdB)
Originally Posted by ali3nn
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.
-
Apr 8th, 2018, 05:37 AM
#6
Re: How to create relationship between tables vb.net (localdB)
Originally Posted by ali3nn
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.
-
Apr 9th, 2018, 06:19 PM
#7
Thread Starter
Lively Member
Re: How to create relationship between tables vb.net (localdB)
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
-
Apr 9th, 2018, 08:57 PM
#8
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.
-
Apr 10th, 2018, 05:51 AM
#9
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|