PC Review


Reply
Thread Tools Rate Thread

Datarelation handling

 
 
Rob W via DotNetMonster.com
Guest
Posts: n/a
 
      31st Oct 2005
Hi

I've created a datarelation between two tables in a dataset which works fine.
What I need to be able to handle is if there are entries in the child table
that don't match those in the parent then ignore them (the children).

In the code below if no records match in the custSQL query then the
datarelation will fail...

Any ideas would be great.

Dim custSQL As String = " Select distinct(a.retail_customer_Id), a.
retailer_id, Forename, Surname" & _
" from web_contact_history a, web_customers b
" & _
" where a.retail_customer_id = b.
retail_customer_id " & _
" and a.retailer_id = " & rtID & _
" and source_system_id = 'CVO' " & _
" and list_id = " & cvoID & _
" order by a.retail_customer_id "

Dim vehSQL As String = " select retail_customer_id, Vin, model,
cvo_retailer_id " & _
" from web_contact_history " & _
" where retailer_id = " & rtID & _
" and source_system_id = 'CVO' " & _
" and list_id = " & cvoID & _
" order by retail_customer_id "


Dim orphDS As DataSet = New DataSet


Dim rlConn As New OleDbConnection(connDB)
rlConn.Open()

Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(custSQL, rlConn)

custDA.Fill(orphDS, "Customers")

Dim vehDA As OleDbDataAdapter = New OleDbDataAdapter(vehSQL, rlConn)
vehDA.Fill(orphDS, "Vehicles")


Dim orphDR_cust2veh = New DataRelation("cust2veh", orphDS.Tables
("Customers").Columns("retail_customer_id"), orphDS.Tables("Vehicles").
Columns("retail_customer_id"))
orphDS.Relations.Add(orphDR_cust2veh)


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...o-net/200510/1
 
Reply With Quote
 
 
 
 
Robbe Morris [C# MVP]
Guest
Posts: n/a
 
      31st Oct 2005
You'll need to (and probably should) manage that in
your sql statement for retrieving children. Only
retrieve those that have a parent in table 1.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net





"Rob W via DotNetMonster.com" <u12359@uwe> wrote in message
news:56abf81f9a1e8@uwe...
> Hi
>
> I've created a datarelation between two tables in a dataset which works
> fine.
> What I need to be able to handle is if there are entries in the child
> table
> that don't match those in the parent then ignore them (the children).
>
> In the code below if no records match in the custSQL query then the
> datarelation will fail...
>
> Any ideas would be great.
>
> Dim custSQL As String = " Select distinct(a.retail_customer_Id), a.
> retailer_id, Forename, Surname" & _
> " from web_contact_history a, web_customers
> b
> " & _
> " where a.retail_customer_id = b.
> retail_customer_id " & _
> " and a.retailer_id = " & rtID & _
> " and source_system_id = 'CVO' " & _
> " and list_id = " & cvoID & _
> " order by a.retail_customer_id "
>
> Dim vehSQL As String = " select retail_customer_id, Vin, model,
> cvo_retailer_id " & _
> " from web_contact_history " & _
> " where retailer_id = " & rtID & _
> " and source_system_id = 'CVO' " & _
> " and list_id = " & cvoID & _
> " order by retail_customer_id "
>
>
> Dim orphDS As DataSet = New DataSet
>
>
> Dim rlConn As New OleDbConnection(connDB)
> rlConn.Open()
>
> Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(custSQL,
> rlConn)
>
> custDA.Fill(orphDS, "Customers")
>
> Dim vehDA As OleDbDataAdapter = New OleDbDataAdapter(vehSQL,
> rlConn)
> vehDA.Fill(orphDS, "Vehicles")
>
>
> Dim orphDR_cust2veh = New DataRelation("cust2veh", orphDS.Tables
> ("Customers").Columns("retail_customer_id"), orphDS.Tables("Vehicles").
> Columns("retail_customer_id"))
> orphDS.Relations.Add(orphDR_cust2veh)
>
>
> --
> Message posted via DotNetMonster.com
> http://www.dotnetmonster.com/Uwe/For...o-net/200510/1



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      1st Nov 2005
Rob,

This should be in my opinion a one time operation. In a relational database
relation can parents have no children, however children can never have no
parents.

So I am a little bit curious about why this is needed, this not curious for
me, however to understand better your problem.

Cor


 
Reply With Quote
 
Lostdante via DotNetMonster.com
Guest
Posts: n/a
 
      1st Nov 2005
Cor Ligthert [MVP] wrote:
>Rob,
>
>This should be in my opinion a one time operation. In a relational database
>relation can parents have no children, however children can never have no
>parents.
>
>So I am a little bit curious about why this is needed, this not curious for
>me, however to understand better your problem.
>
>Cor



Thanks for the replies..

The problem I have is that I report of two tables, a customer table and a
contacts table. I get parent data from the customer table where there is an
entry in the contacts table. Then children from the contacts table where they
meet criteria. What's happened is that there are contact entries that meet
the criteria which have yet to have customer data added. So I have the
situation of children with no perants. Unfortunately I have no control over
the data integrity and the business want to see all the contact entries
regardless of the customer data.

If there's no way of catching exceptions for a data relation then i'll work
something out in the sql.


--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      1st Nov 2005
Than you can not use a datarelation direct.

You can try to get a distinct table from your children (only the keys).

Than you can probably make a datarelation from that distinct table to what
you call your parents and to the childtable.

I hope that this gives an idea.

Cor


 
Reply With Quote
 
Lostdante via DotNetMonster.com
Guest
Posts: n/a
 
      1st Nov 2005
Cor Ligthert [MVP] wrote:
>Than you can not use a datarelation direct.
>
>You can try to get a distinct table from your children (only the keys).
>
>Than you can probably make a datarelation from that distinct table to what
>you call your parents and to the childtable.
>
>I hope that this gives an idea.
>
>Cor


Thanks for the replies. I managed to solve this using an outer join in the
parent query so there are no longer any orphaned records and the datarelation
now works.


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...o-net/200511/1
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataRelation Tony Johansson Microsoft C# .NET 0 24th Jun 2009 09:03 PM
Custom Event handling + thread handling. Michael McCarthy Microsoft C# .NET 1 14th Jun 2005 02:50 AM
Question about best practices with SqlConnection, error handling and memory handling Lars-Erik Aabech Microsoft ADO .NET 9 17th Apr 2004 06:11 PM
ADO.NET DataRelation Tim Microsoft ADO .NET 1 20th Jan 2004 08:18 AM
datarelation Marco Martin Microsoft C# .NET 1 20th Dec 2003 01:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:53 AM.