Advertisement

07.20.2007 at 01:09AM PDT, ID: 22709128
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Adding relationship between tables in dataset

Tags: dataset, tables, between, relationship
while working on vb.net I am trying to  add multiple tables with different columns to the single datagrid but no luck so far

Can some please provide me a Sample code for how to create two tables and then add a relationship betwen them and finally add them to single dataset which i will bind to the ultragrid

Thanks
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: shieldguy
Solution Provided By: DarrenD
Participating Experts: 1
Solution Grade: B
Views: 165
Translate:
Loading Advertisement...
07.20.2007 at 02:09AM PDT, ID: 19529574

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 02:10AM PDT, ID: 19529577

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 02:11AM PDT, ID: 19529581

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 02:16AM PDT, ID: 19529597

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 02:25AM PDT, ID: 19529630

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 02:27AM PDT, ID: 19529640

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 02:41AM PDT, ID: 19529706

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 02:48AM PDT, ID: 19529729

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 03:59AM PDT, ID: 19529978

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 04:09AM PDT, ID: 19530011

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 04:19AM PDT, ID: 19530048

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 04:34AM PDT, ID: 19530093

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.20.2007 at 04:35AM PDT, ID: 19530099

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
07.20.2007 at 02:09AM PDT, ID: 19529574

Rank: Master

 
07.20.2007 at 02:10AM PDT, ID: 19529577

Rank: Master

I have it done in C# myself if you want me to post this and you could convert it to VB.NET

Let me know

Darren
 
07.20.2007 at 02:11AM PDT, ID: 19529581
 
07.20.2007 at 02:16AM PDT, ID: 19529597
 
07.20.2007 at 02:25AM PDT, ID: 19529630
I really appriciate if you could post that C# exxample I will convert it in vb.net
 
07.20.2007 at 02:27AM PDT, ID: 19529640
The table I am adding in single dataset they dont have any kind of relationship between them and also they have different numbers of columns as well

 
07.20.2007 at 02:41AM PDT, ID: 19529706

Rank: Master

Here you go,

I use stored procedures to retrieve my data. Basically this just calles two select statements in on SP and then I add the rlationship.

The last link I posted is very straight forward from a VB.NET point of view. The first two might have a little more waffle associated with them

public DataSet ExecuteSPQuery(string sConnection, string sStoredProcName)
{

// using guarantees that Dispose is called on m_oconn, which will close the connection.
using (m_oconn = new SqlConnection(sConnection))
{

      // Set the Command propeties.
                m_cmd = new SqlCommand() ;      
                m_cmd.CommandText = sStoredProcName ;
      m_cmd.Connection = m_oconn ;
      m_cmd.CommandType = CommandType.StoredProcedure ;

      DataSet dataSet = new DataSet (sStoredProcName) ;
      SqlDataAdapter adapter = new SqlDataAdapter(m_cmd) ;

      // Open the connection to the database.
      m_oconn.Open() ;

      // Run the stored Procedure and place the results in dataTable.
      adapter.Fill(dataSet) ;

      // Create the array of Parent and Child columns.
      DataColumn ParentCol ;
      DataColumn ChildCol ;

      ParentCol = new DataColumn ;
      ChildCol = new DataColumn ;

      // Set the name of the parent column to hold the relationship.
      ParentCol = dataSet.Tables[0].Columns["NameOfParentCol"] ;
                              
      // Set the name of the child column to hold the relationship.
      ChildCol = dataSet.Tables[1].Columns["NameOfChildCol"] ;

      // Create the relationship
      DataRelation Rel = new DataRelation("NameOfRelationship", ParentCol, ChildCol) ;

      // Add the newly created relationship to the dataset.
      dataSet.Relations.Add(Rel) ;
      
      return dataSet ;
}
}

Hope this helps,

Darren
      
 
07.20.2007 at 02:48AM PDT, ID: 19529729

Rank: Master

"The table I am adding in single dataset they dont have any kind of relationship between them and also they have different numbers of columns as well"

It does not matter about the number of columns in each table but you do need to have some relationship between the two in order to add a relationship.

Otherwise you can just add the two tables without a relationship but they will not display as you want in the datagrid.

You should look at adding a foregin key to one of the table if there isn't one there and then when the relationship is added they will display properly in the datagrid.

Darren

 
07.20.2007 at 03:59AM PDT, ID: 19529978
I tried you code but now i am getting the following error at following line

"        Dim Rel As DataRelation = New DataRelation("NameOfRelationship", dc1, dc2)     "


ERROR:
{"'column' argument cannot be null.
Parameter name: column"}

CODE:
       dsNew = objSitereport.GetTable(arrLocation, intPeriodId)

        Dim dc1 As New DataColumn
        Dim dc2 As New DataColumn

        dc1 = dsNew.Tables(0).Columns("p_emp_id")
        dc2 = dsNew.Tables(1).Columns("p_emp_id")

        Dim Rel As DataRelation = New DataRelation("NameOfRelationship", dc1, dc2)

        dsNew.Relations.Add(Rel)
 
07.20.2007 at 04:09AM PDT, ID: 19530011

Rank: Master

Hi,

Put a break on the line:
'Dim Rel As DataRelation = New DataRelation("NameOfRelationship", dc1, dc2)'
and check the value of dc1 and dc2 and see if either of them are null.

Is there a column called p_emp_id in both tables within the dataset?

Darren
 
07.20.2007 at 04:19AM PDT, ID: 19530048
ok I fixed it now actually the first column is emp_id but their is no name defined so i replace it with 0 index but now i am getting error on following line

" dsNew.Relations.Add(Rel) "

ERROR:
{"This constraint cannot be enabled as not all values have corresponding parent values."}

CODE:
        dsNew = objSitereport.GetTable(arrLocation, intPeriodId)

        Dim dc1 As New DataColumn
        Dim dc2 As New DataColumn

        dc1 = dsNew.Tables(0).Columns(0)
        dc2 = dsNew.Tables(1).Columns(0)

        Dim Rel As DataRelation = New DataRelation("NameOfRelationship", dc1, dc2)

        dsNew.Relations.Add(Rel)

        Me.UltraGrid1.DataSource = dsNew
 
07.20.2007 at 04:34AM PDT, ID: 19530093

Rank: Master

Hi,

This means that there are values in the child table which do not have corresponding values in the parent table.

You will have to a test on your database to see what values in the parent id do not have values in the child.

Basically you don't have any relationship on the two tables within the database so the data is not in sync.

You can't have a child with no linking parent. It would never make sense.

Hope this helps.

Cheers,

Darren

 
07.20.2007 at 04:35AM PDT, ID: 19530099

Rank: Master

You will have to a test on your database to see what values in the parent id do not have values in the child.

should be...

You will have to a test on your database to see what values in the child id do not have values in the parent.
Accepted Solution
 
 
20080236-EE-VQP-29