Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All -

I have a very simple question, but hard to understand for me. I am trying to create a database application in C# (Winforms).I have a database in Visual Studio. In the DataSet I created relationships. Now, in my Data Source when I expand a table I see another table inside it, and I can expand that table too.

The confusion I am having - All 4 tables are connected in one way or another and when you expand a table there is a table that resides in that table, however, the nested table also resides in other table. How do I know which table to use when I drag the column onto the form?

Can anyone point me to where I can learn exactly how the tables are assigned in the Data Source and when the relationship is created - how do you know which table to use on the forms?

I hope this makes sense.

Update to question:

C#
Thanks for the replies. Yes, the relationships are very obvious to me since I created them. However, not sure if I am doing it the best way, but after I create the relationships - I always drag the fields from the Data Source Window over to the form, and that creates the Binding Source and Navigator.

Before I create the relationships:

tblClient
ClientID
FirstName
LastName

tblFile
FileID
ClientID
FileNumber
FileDate

tblReceipts
ReceiptID
FileID
ReceiptNumber
ReceiptDate

tblCoSigner
CoSignerID
ReceiptID
CoFirstName
CoLastName

Then my relationships look like this:

tblClient - tblFile (1 to many)
tblFile - tblReceipts (1 to many)
tblReceipts - tblCoSigner (1 to many)

After the relationships the Data Source Window now has:

Client Table
ClientID
FirstName
LastName
-tblFile
FileID
CleintID
FileNumber
Date
-tblReceipts
ReceiptID
FileID
ReceiptNumber
-tblCosigner
CosignerID
ReceiptID
CoFirstName
CoLastName

tblFile
FileID
ClientID
FileNumber
Date
-tblReceipts
ReceiptID
FileID
ReceiptNumber
-tblCoSigner
CosignerID
ReceiptID
CoFirstName
CoLastName

So with the above, you see how tblCoSigner was placed in two different tables, as well as, outside of the table. Also, the other tables are placed inside other tables that there is a relationship with. When I drag a column over to the form to create the binded text box, how do I know for sure which ones are going to use the relationship when they are a child of several other parent tables.

Hope this make sense in trying to make this easier for you.


What I have tried:

google and trying to figure it out myself.
Posted
Updated 12-May-16 5:49am
v2
Comments
George Jonsson 1-May-16 22:17pm    
It sort of doesn't make sense.
Did you create the DataSet yourself or do you get it auto-generated by using a DataAdapter and fill via a SQL query to a database?
Also it would be easier to answer of you showed the relationships between the tables and how you want to present the data in the form.
daveofgv 1-May-16 23:00pm    
That is a fair question. I am sorry I didn't explain it all the way.

I created a database in SQLite (outside of Visual Studio). I clicked "New Data Source" and connected to the already made database. I then opened the Data Source Designer and created the relationships there. After you save it the Data Source now has tables within tables since they now have relationships. I have a picture, but cannot see where to upload it for your viewing.

It would be a lot easier if I uploaded a picture so you can see. Is there a way I can send you a pic?
George Jonsson 1-May-16 23:35pm    
Nah, no emails if I can avoid it.
What you can do is to show the tables in text like


Table1 Table2 Table3
ID ID ID
Column1 Table1_ID Table2_ID
etc etc etc

The relations are kind of obvious.
You could also update your question with the XSD file if it is not too big.

You need to explain what data you want to present and how.

My best tip is to read up on the BindingSource Class (System.Windows.Forms)[^]

And are you working in Windows Forms or ASP or what?
Patrice T 2-May-16 0:15am    
Should be obvious if you did the design.
daveofgv 2-May-16 9:59am    
Thanks for the replies. Yes, the relationships are very obvious to me since I created them. However, not sure if I am doing it the best way, but after I create the relationships - I always drag the fields from the Data Source Window over to the form, and that creates the Binding Source and Navigator.

Before I create the relationships:

tblClient
ClientID
FirstName
LastName

tblFile
FileID
ClientID
FileNumber
FileDate

tblReceipts
ReceiptID
FileID
ReceiptNumber
ReceiptDate

tblCoSigner
CoSignerID
ReceiptID
CoFirstName
CoLastName

Then my relationships look like this:

tblClient - tblFile (1 to many)
tblFile - tblReceipts (1 to many)
tblReceipts - tblCoSigner (1 to many)

After the relationships the Data Source Window now has:

Client Table
ClientID
FirstName
LastName
-tblFile
FileID
CleintID
FileNumber
Date
-tblReceipts
ReceiptID
FileID
ReceiptNumber
-tblCosigner
CosignerID
ReceiptID
CoFirstName
CoLastName

tblFile
FileID
ClientID
FileNumber
Date
-tblReceipts
ReceiptID
FileID
ReceiptNumber
-tblCoSigner
CosignerID
ReceiptID
CoFirstName
CoLastName

So with the above, you see how tblCoSigner was placed in two different tables, as well as, outside of the table. Also, the other tables are placed inside other tables that there is a relationship with. When I drag a column over to the form to create the binded text box, how do I know for sure which ones are going to use the relationship when they are a child of several other parent tables.

Hope this make sense in trying to make this easier for you.

I figured out the question I had. First, I had to find the top level table and then in the data source all the tables are within each other, if you dig down far enough. Since I wasn't looking at the top level - I didn't see where all the relationships were held together.

This can be closed.
 
Share this answer
 
Please mark your answer as the right answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900