Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exception while creating relation in Dataset

Posted on 2009-04-09
31
Medium Priority
?
352 Views
Last Modified: 2013-12-17
Hi Experts,
I am having a dataset which contains two tables.
I am trying establish relation between them,but I am getting an exception

'column' argument cannot be null.
Parameter name: column

What could be the reason?
0
Comment
Question by:johny_bravo1
[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
  • 17
  • 9
  • 4
  • +1
31 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 24106793
code, please.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24106829
Hi p_davis,
that exception is resolved but I am getting another exception now
""These columns don't currently have unique values.""

 dsShipper_master = objShipperInfo.getShipperInfo_Hierarchy(status);
 DataRelation rel = new DataRelation("Root", dsShipper_master.Tables["Table"].Columns["ShipperId"], dsShipper_master.Tables["Table1"].Columns["ShipperId"]);
 dsShipper_master.Relations.Add(rel);

Following is the SP;
  
alter PROCEDURE [dbo].[getShipperInfo_Hierarchy]  
@Status varchar(20)  
AS  
BEGIN  
 
  
 IF @Status = 'Active'  
 BEGIN  
  SELECT  sm.ShipperName,  
    sm.ShipperType,  
    lm.LocationName+' ('+lm.Loc_Type+')' as LocationName,  
    lm.Address1+', '+lm.Address2+', '+lm.City+', '+lm.State+', '+lm.Zip as Address,  
    lm.LocationId,  
    sm.ShipperId  
  FROM dbo.TMSShipper_Master sm,  
     dbo.TMSLocation_Master lm  
  WHERE sm.ShipperId = lm.Loc_ShipperId and  
       sm.IsActive = '1'  
  order by ShipperName  
 
 SELECT  
    lm.LocationName+' ('+lm.Loc_Type+')' as LocationName,  
    lm.Address1+', '+lm.Address2+', '+lm.City+', '+lm.State+', '+lm.Zip as Address,  
    sm_mc.ContactName,  
    sm_mc.Phone,  
    sm_mc.email,  
  sm_mc.ShipperId,
    lm.LocationId
      FROM    dbo.TMSShipper_MasterMoreContact sm_mc,  
   dbo.TMSLocation_Master lm  
  WHERE   lm.LocationId = sm_mc.loc_ShipperId
  
 END  
 ELSE  
 IF @Status = 'Inactive'  
 BEGIN  
  SELECT  sm.ShipperName,  
    sm.ShipperType,  
    lm.LocationName+' ('+lm.Loc_Type+')' as LocationName,  
    lm.Address1+', '+lm.Address2+', '+lm.City+', '+lm.State+', '+lm.Zip as Address,  
    sm_mc.ContactName,  
    sm_mc.Phone,  
    sm_mc.email,  
    lm.LocationId,  
    sm.ShipperId  
  FROM dbo.TMSShipper_Master sm,  
   dbo.TMSShipper_MasterMoreContact sm_mc,  
   dbo.TMSLocation_Master lm  
  WHERE sm.ShipperId = sm_mc.ShipperId and  
    lm.LocationId = sm_mc.loc_ShipperId and  
    sm.IsActive = '0'   
  order by ShipperName  
 END  
 ELSE  
 BEGIN  
  SELECT  sm.ShipperName,  
    sm.ShipperType,  
    lm.LocationName+' ('+lm.Loc_Type+')' as LocationName,  
    lm.Address1+', '+lm.Address2+', '+lm.City+', '+lm.State+', '+lm.Zip as Address,  
    sm_mc.ContactName,  
    sm_mc.Phone,  
    sm_mc.email,  
    lm.LocationId,  
    sm.ShipperId  
  FROM dbo.TMSShipper_Master sm,  
   dbo.TMSShipper_MasterMoreContact sm_mc,  
   dbo.TMSLocation_Master lm  
  WHERE sm.ShipperId = sm_mc.ShipperId and  
    lm.LocationId = sm_mc.loc_ShipperId    
 --   sm_mc.ContactId in (select min(ContactId)  
 --  from dbo.TMSShipper_Master sm,dbo.TMSShipper_MasterMoreContact sm_mc,dbo.TMSLocation_Master lm  
 --  where sm.ShipperId = sm_mc.ShipperId and lm.LocationId = sm_mc.loc_ShipperId  
 --  group by sm_mc.loc_ShipperId)  
  order by ShipperName  
 END  
  
END  

Open in new window

0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24106847
the column ShipperId may not exist in either dsShipper_master.Tables["Table"] or
dsShipper_master.Tables["Table1"]
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24106863
change to  

dsShipper_master = objShipperInfo.getShipperInfo_Hierarchy(status);
 
if(dsShipper_master.Tables["Table"].Columns["ShipperId"] != null && 
dsShipper_master.Tables["Table1"].Columns["ShipperId"] != null)
{
 DataRelation rel = new DataRelation("Root", dsShipper_master.Tables["Table"].Columns["ShipperId"], dsShipper_master.Tables["Table1"].Columns["ShipperId"]);
 dsShipper_master.Relations.Add(rel);
}

Open in new window

0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24106883
It is going inside if and throwing the same exception
"These columns don't currently have unique values."
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24106908
Check both tables either in one of table the column is not the primary column or you have inserted some duplicate values in one of the table.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24106941
Please look at the SP.
I have used three different tables.
Check wehn the Status='Active'
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24106946
is shipperId the primary key for the TMSShipper_Master table?
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24106972
yes
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24106989
and even in TMSShipper_MasterMoreContact is set as Foreign Key
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24106997
sorry that is in TMSShipper_MasterMoreContact , shipperId is foreign key
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24107003
what type of object is that key -- is it numeric?
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24107004
like int?
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24107022
yup,its int.
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 2000 total points
ID: 24107024
yep according to the query u wont have unique values for Shipper_id in either of the tables. and hence u cant set a relation between them.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24107116
So you want me to put distinct for ShipperId.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24107144
Even then it will not return Unique ShipperId as data will be repeated according to Location and contacts.
Any other idea?
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24107150
Surprisingly if I bind only tables.I mean If i have three selects for three tables.
I am able to create relation between them.
0
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 2000 total points
ID: 24107152
this wont be possible if u have multiple locations for a shipper. if u need a master table then u will need another table in the data set which will list all the shipper and u will have relations like
ShipperTable - > Table
ShipperTable -> Table1
u cant set direct relations between Table and Table1
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24107189
Ya one shipper may have multiple location.
So what needs to be changed?
0
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 2000 total points
ID: 24107252
u will need another table to list the shippers. u will need to change the proc to add a new select which will be
  SELECT   sm.ShipperId  
  FROM dbo.TMSShipper_Master sm,  WHERE  sm.IsActive = '1'  
this is for the active section..like wise u have to add for other sections
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24107275
Ok I have included one more select statement in the procedure,for getting shipperid.Now I am establishing relation between Table<-->Table1,Table<-->Table2
This relation works.
But the problem is that I am binding this to Farpoint and it is adding one more Hierarchy.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24107294
Thanks Experts for ur valuable comments.
I will be able to check it tomorrow so If you post any comment I will try it tomoroow.
Again thanks for ur help.
If u post any suggestions I will be able to work on it tomorrow.Thanks.
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24107303
that is the only way u can establish relations considering ur situation
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24107322
Ohh ok!
I will try something different or try to change the display structure.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24107331
Thanks gauthampj.I am not closing this question,hoping that I may need some more guidance from you.
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24107347
sure..:-)..always a pleasure
0
 

Expert Comment

by:mulpuri05
ID: 24120028

Use distinct to below queary. It should return "shipperId" unique vlaue like "1,2,3,4" .I sould not contain duplicate values than only you can have your relation.Do you want this solution for reapeater.

SELECT  sm.ShipperName,  
    sm.ShipperType,  
    lm.LocationName+' ('+lm.Loc_Type+')' as LocationName,  
    lm.Address1+', '+lm.Address2+', '+lm.City+', '+lm.State+', '+lm.Zip as Address,  
    lm.LocationId,  
    sm.ShipperId  
  FROM dbo.TMSShipper_Master sm,  
     dbo.TMSLocation_Master lm  
  WHERE sm.ShipperId = lm.Loc_ShipperId and  
       sm.IsActive = '1'  
  order by ShipperName  
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24124785
I m using this for FarPont and not for repeater.
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24125702
even if u use distinct since u have multiple locations for a shipper, shipper id will be duplicated
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24129445
Hii
can I create relation something like this,I am missing some syntax here,
DataRelation rel = new DataRelation("Root", dsShipper.Tables["Table"].Columns["ShipperId","LocationId"], dsShipper.Tables["Table1"].Columns["ShipperId","LocationId"]);
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 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