Solved

VB.net automatically detect SQL table relationships

Posted on 2014-11-15
7
212 Views
Last Modified: 2014-11-16
Hi

I have a SQL database where relationships have been set up between all the tables.
I want to allow the user of my VB.net app to select columns from multiple tables, where
the table relationships are automatically detected and used in the code to pull the data
through to a DataGridView. How do I achieve this? Do I use a DataSet?
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40444429
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40444430
First you need to decide on which technology you will be using to access the database? For example Standard ADO .Net, Linq to Sql or Linq to Entity Framework?

Which SQL server are you using?

To your statement, "I want to allow the user of my VB.net app to select columns from multiple tables, where
the table relationships are automatically detected and used in the code to pull the data
through to a DataGridView", this is not done automatically for you. You will need to build a SQL statement for each request that will return the needed fields / columns back from the desired tables.
0
 

Author Comment

by:Murray Brown
ID: 40444535
Hi Phillip. Thanks for referencing my other question. I hadn't realised that table relations could be added to a dataset until today so I am happy to find that there is a a different route
Hi Fernando. I am using the sqlclient namespace in I think ADO.net. My database is a sql server 2008 database
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:Murray Brown
ID: 40445225
So what is the best way to pull multiple joined table data through in VB.net. I also want my users to be able to name and save a view for each scenario
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40445730
As I stated earlier there is no programming option that will do that automatically for you. Seeming that you want to allow the user to pick and choose which columns to download from the tables, joined or not, you will need to formulate a SQL statement that will query the database and bring down the wanted information, which will not be an easy feat. This means that the application must have a very good knowledge of the database structure, for example what columns are in what table they are in and if multiple tables are involved how to join the two between the two or more tables.

Here is a class that will help to do what you need a little easier and can be found on GitHub, DbExtensions SqlBuilder. I have not used this code before an so I can not say how well it performs. I understand that this code can be downloaded into your application using NuGet
0
 

Author Closing Comment

by:Murray Brown
ID: 40445742
Thanks very much Fernando. I appreciate the help
Murray
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40445747
Not a problem Murray, glad to help.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question