Data set relation problem

Posted on 2006-06-10
Last Modified: 2010-04-23
I use the following code to retrieve two datasets and create a relationship

      Dim Command As New OleDbCommand
      adItems = New OleDbDataAdapter
      dtItems = New DataTable
      adItemGridPackage = New OleDbDataAdapter
      dtItemGridPackage = New DataTable
      fSql = " SELECT ContractItems.* " _
         & "FROM(ContractItems) " _
         & "WHERE (((ContractItems.txtContractNumber)= " & oContract.ContractNumber & ") AND ContractItems.blnPackageSubItem = 0) " _
         & "ORDER BY ContractItems.blnLaborOnly DESC; "
      Command.Connection = oContract.OpenConnection
      Command.CommandText = fSql
      adItems.SelectCommand = Command

      ' get the package sub items
      fSql = " SELECT ContractItems.* " _
         & "FROM(ContractItems) " _
         & "WHERE (((ContractItems.txtContractNumber)= " & oContract.ContractNumber & ") AND ContractItems.blnPackageSubItem <> 0) "

      Command.CommandText = fSql
      adItemGridPackage.SelectCommand = Command
      Command = Nothing
      'build the data set
      dsGridItems = New DataSet
      ParentColumn = New DataColumn
      ParentColumn = dtItems.Columns("txtContractItemGuid")
      ChildColumn = New DataColumn
      ChildColumn = dtItemGridPackage.Columns("txtContractItemGuid")
      relPackage = New DataRelation("Package", ParentColumn, ChildColumn)
      dsGridItems.Relations.Add(relPackage)                 **************************This line*********************

The marked line throws an error "The columns don't current have unique values".   Even with this error the relationship is created and the grid that has the dataset as it source displays correctly.  The only thing I see is that both datatables have the same table as the source. Perhaps this causes a problem.  What am I doing wrong?  
Question by:Moed
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
  • 4
  • 3
LVL 11

Accepted Solution

anyoneis earned 250 total points
ID: 16878527
There error message means that dtItems has more than one row with the same txtContractItemGuid. Otherwise, what you are doing should work.  


Author Comment

ID: 16881042
If you look at the sql you'll see that I use the  ContractItems.blnPackageSubItem <> 0 or ContractItems.blnPackageSubItem = 0 to get the correct records.  Is it considered grossly poor design to just ignore the error?  For this particular application I don't really see a reason to create and maintain another whole table unless I am asking for problems down the road.
LVL 11

Expert Comment

ID: 16881365
>>  Is it considered grossly poor design to just ignore the error


I can't say. I know I would not be able to ignore the error.

I should have asked some more questions about txtContractItemGuid. Is this column nullable?
Do all rows have a unique value here, or are there some rows that share the same value?

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 16885809
Sleeping could be a problem.   Here's the way it works.  Some of the product that we order, lets say a toilet, is sold in three parts.  1. tank 2. bowl 3. seat.  It's difficult to teach an entry person all the different parts for all the different products so when I input an item in the products table I input all the parts as seperate items then input a master description item.  This is all in the same table.  Then I assign the parts to the master item via a reference in a 2nd table.  When the user takes off the master item it pulls all the parts into the order assigns a guid to the parts and the master description and sets the blnPackageSubItem to true on all the items.  The master description is just shown to group all the parts.  Thats why I get the relation error.  The guid is unique to the group but its the blnPackageSubItem field that actually seperates the description item from the items that need ordered.  Hope that helps a little in your evaluation of the problem.
LVL 11

Expert Comment

ID: 16887105
>>The guid is unique to the group but its the blnPackageSubItem ....

Unique to the group is not enough. A relation requires that the parent column be unique to the row, so that when you ask it to navigate from child to parent, it can yield a single result.


Author Comment

ID: 16887863
Ok,  I'll back up and do it right.  Thanks for the help.
LVL 11

Expert Comment

ID: 16888487
Maybe you can add a column or two to the relation, thereby making it unique.

One route would be to take blnPackageSubItem and change it from bool to int, give the main item a value of 0 and incrementally assign numbers to the subitems. Then, you would add this column to the datarelation.


Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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