PC Review


Reply
Thread Tools Rate Thread

Combining fields from different tables into 1 dataset

 
 
=?Utf-8?B?am9uZWZlcg==?=
Guest
Posts: n/a
 
      28th Dec 2005
So far the dataset just shows
Type, Benefit, Change

I want it to show
Type, Benefit, Change, Description

This should be a pretty elementary question - and I've spent 2 days on it
already.
I just want to add one field from another table into my dataset, should be
easy, but maybe it's the way it is related that is making it so difficult
(there are no totally unique fields in either table, so it needs a multi-join)

I have 2 tables in the dataset already:
Membership
BENFT

To get the Desc Field from the BENFT table, I need to relate 2 fields to
Membership
Membership.Benefit = BENFT.BNFT
Membership.Change = BENFT.BCHG


'This is what I tried so far, but it's not working
daBenefits.Fill(DsBenefits1, "Membership")

Dim relBenefit As New DataRelation("relBen",
DsBenefits1.Tables(0).Columns("Benefit"),
DsBenefits1.Tables(1).Columns("BNFT"))
Dim relBenChg As New DataRelation("relChg",
DsBenefits1.Tables(0).Columns("Change"),
DsBenefits1.Tables(1).Columns("BCHG"))

DsBenefits1.Relations.Add(relBenefit)
DsBenefits1.Relations.Add(relBenChg)


daBenefitDesc.Fill(DsBenefits1, "BENFT")



'DGMembers is the DataGrid
DGBenefits.DataSource =
DsBenefits1.Tables("Membership").DefaultView
DGBenefits.DataBind()

Thank you

Note: Membership is actually a union that I have filled for each piece into
the dsBenefits1



 
Reply With Quote
 
 
 
 
W.G. Ryan - MVP
Guest
Posts: n/a
 
      28th Dec 2005
Jonefer: Have you considered using DataSet.Merge? This would entail two
datasets (so you'd have to move/copy the datatable) but I think it'd give
you what you wanted.
"jonefer" <(E-Mail Removed)> wrote in message
news:855BAAC2-0C12-4FAE-8BE6-(E-Mail Removed)...
> So far the dataset just shows
> Type, Benefit, Change
>
> I want it to show
> Type, Benefit, Change, Description
>
> This should be a pretty elementary question - and I've spent 2 days on it
> already.
> I just want to add one field from another table into my dataset, should be
> easy, but maybe it's the way it is related that is making it so difficult
> (there are no totally unique fields in either table, so it needs a
> multi-join)
>
> I have 2 tables in the dataset already:
> Membership
> BENFT
>
> To get the Desc Field from the BENFT table, I need to relate 2 fields to
> Membership
> Membership.Benefit = BENFT.BNFT
> Membership.Change = BENFT.BCHG
>
>
> 'This is what I tried so far, but it's not working
> daBenefits.Fill(DsBenefits1, "Membership")
>
> Dim relBenefit As New DataRelation("relBen",
> DsBenefits1.Tables(0).Columns("Benefit"),
> DsBenefits1.Tables(1).Columns("BNFT"))
> Dim relBenChg As New DataRelation("relChg",
> DsBenefits1.Tables(0).Columns("Change"),
> DsBenefits1.Tables(1).Columns("BCHG"))
>
> DsBenefits1.Relations.Add(relBenefit)
> DsBenefits1.Relations.Add(relBenChg)
>
>
> daBenefitDesc.Fill(DsBenefits1, "BENFT")
>
>
>
> 'DGMembers is the DataGrid
> DGBenefits.DataSource =
> DsBenefits1.Tables("Membership").DefaultView
> DGBenefits.DataBind()
>
> Thank you
>
> Note: Membership is actually a union that I have filled for each piece
> into
> the dsBenefits1
>
>
>



 
Reply With Quote
 
=?Utf-8?B?am9uZWZlcg==?=
Guest
Posts: n/a
 
      29th Dec 2005
Bill, please help me out. Something as simple as:

SELECT Benefit, Type, Charge, MRN, [GROUP], SGR, BENFT.BNFT_DESC
FROM Membership INNER JOIN BENFT ON (Charge = BENFT.BCHG) AND (Benefit =
BENFT.BNFT);

...should STILL be simple in ADO.NET. Perhaps you think I am asking for
something more difficult?

It's pretty trivial in Access: pull two tables in, connect the two related
fields:

Yet, I've spent two days reading and looking at different posts and sites.
If ADO.NET is really supposed to help make working with databases simpler, I
haven't been convinced yet. I'm talking about adding one field from another
table to a dataset.

Could you or someone just give me the steps? Because I can't search anymore
sites in google to find the answer to this question. I'll read more about it
after I digest how to do something so simple.


"W.G. Ryan - MVP" wrote:

> Jonefer: Have you considered using DataSet.Merge? This would entail two
> datasets (so you'd have to move/copy the datatable) but I think it'd give
> you what you wanted.
> "jonefer" <(E-Mail Removed)> wrote in message
> news:855BAAC2-0C12-4FAE-8BE6-(E-Mail Removed)...
> > So far the dataset just shows
> > Type, Benefit, Change
> >
> > I want it to show
> > Type, Benefit, Change, Description
> >
> > This should be a pretty elementary question - and I've spent 2 days on it
> > already.
> > I just want to add one field from another table into my dataset, should be
> > easy, but maybe it's the way it is related that is making it so difficult
> > (there are no totally unique fields in either table, so it needs a
> > multi-join)
> >
> > I have 2 tables in the dataset already:
> > Membership
> > BENFT
> >
> > To get the Desc Field from the BENFT table, I need to relate 2 fields to
> > Membership
> > Membership.Benefit = BENFT.BNFT
> > Membership.Change = BENFT.BCHG
> >
> >
> > 'This is what I tried so far, but it's not working
> > daBenefits.Fill(DsBenefits1, "Membership")
> >
> > Dim relBenefit As New DataRelation("relBen",
> > DsBenefits1.Tables(0).Columns("Benefit"),
> > DsBenefits1.Tables(1).Columns("BNFT"))
> > Dim relBenChg As New DataRelation("relChg",
> > DsBenefits1.Tables(0).Columns("Change"),
> > DsBenefits1.Tables(1).Columns("BCHG"))
> >
> > DsBenefits1.Relations.Add(relBenefit)
> > DsBenefits1.Relations.Add(relBenChg)
> >
> >
> > daBenefitDesc.Fill(DsBenefits1, "BENFT")
> >
> >
> >
> > 'DGMembers is the DataGrid
> > DGBenefits.DataSource =
> > DsBenefits1.Tables("Membership").DefaultView
> > DGBenefits.DataBind()
> >
> > Thank you
> >
> > Note: Membership is actually a union that I have filled for each piece
> > into
> > the dsBenefits1
> >
> >
> >

>
>
>

 
Reply With Quote
 
Fox
Guest
Posts: n/a
 
      29th Dec 2005
HI

just try
SELECT Benefit as benefit, Type as type, Charge as Charge, MRN as mrn,
[GROUP] as gp, SGR as sgr, BENFT.BNFT_DESC AS Description
FROM Membership INNER JOIN BENFT ON (Charge = BENFT.BCHG) AND (Benefit =
BENFT.BNFT);

"jonefer" <(E-Mail Removed)> wrote in message
newsE000F81-B96B-4889-9F37-(E-Mail Removed)...
> Bill, please help me out. Something as simple as:
>
> SELECT Benefit, Type, Charge, MRN, [GROUP], SGR, BENFT.BNFT_DESC
> FROM Membership INNER JOIN BENFT ON (Charge = BENFT.BCHG) AND (Benefit =
> BENFT.BNFT);
>
> ..should STILL be simple in ADO.NET. Perhaps you think I am asking for
> something more difficult?
>
> It's pretty trivial in Access: pull two tables in, connect the two related
> fields:
>
> Yet, I've spent two days reading and looking at different posts and sites.
> If ADO.NET is really supposed to help make working with databases simpler,
> I
> haven't been convinced yet. I'm talking about adding one field from
> another
> table to a dataset.
>
> Could you or someone just give me the steps? Because I can't search
> anymore
> sites in google to find the answer to this question. I'll read more about
> it
> after I digest how to do something so simple.
>
>
> "W.G. Ryan - MVP" wrote:
>
>> Jonefer: Have you considered using DataSet.Merge? This would entail two
>> datasets (so you'd have to move/copy the datatable) but I think it'd give
>> you what you wanted.
>> "jonefer" <(E-Mail Removed)> wrote in message
>> news:855BAAC2-0C12-4FAE-8BE6-(E-Mail Removed)...
>> > So far the dataset just shows
>> > Type, Benefit, Change
>> >
>> > I want it to show
>> > Type, Benefit, Change, Description
>> >
>> > This should be a pretty elementary question - and I've spent 2 days on
>> > it
>> > already.
>> > I just want to add one field from another table into my dataset, should
>> > be
>> > easy, but maybe it's the way it is related that is making it so
>> > difficult
>> > (there are no totally unique fields in either table, so it needs a
>> > multi-join)
>> >
>> > I have 2 tables in the dataset already:
>> > Membership
>> > BENFT
>> >
>> > To get the Desc Field from the BENFT table, I need to relate 2 fields
>> > to
>> > Membership
>> > Membership.Benefit = BENFT.BNFT
>> > Membership.Change = BENFT.BCHG
>> >
>> >
>> > 'This is what I tried so far, but it's not working
>> > daBenefits.Fill(DsBenefits1, "Membership")
>> >
>> > Dim relBenefit As New DataRelation("relBen",
>> > DsBenefits1.Tables(0).Columns("Benefit"),
>> > DsBenefits1.Tables(1).Columns("BNFT"))
>> > Dim relBenChg As New DataRelation("relChg",
>> > DsBenefits1.Tables(0).Columns("Change"),
>> > DsBenefits1.Tables(1).Columns("BCHG"))
>> >
>> > DsBenefits1.Relations.Add(relBenefit)
>> > DsBenefits1.Relations.Add(relBenChg)
>> >
>> >
>> > daBenefitDesc.Fill(DsBenefits1, "BENFT")
>> >
>> >
>> >
>> > 'DGMembers is the DataGrid
>> > DGBenefits.DataSource =
>> > DsBenefits1.Tables("Membership").DefaultView
>> > DGBenefits.DataBind()
>> >
>> > Thank you
>> >
>> > Note: Membership is actually a union that I have filled for each piece
>> > into
>> > the dsBenefits1
>> >
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?am9uZWZlcg==?=
Guest
Posts: n/a
 
      29th Dec 2005
I went ahead and tried your suggestion and got the following error
"Join expression not supported"

because I'm trying to make this join AFTER filling a dataset with 9 pieces
of a union query. I'm working with an OleDB Jet 4.0 (access database)

where exactly did you want me to put that sql command?



"Fox" wrote:

> HI
>
> just try
> SELECT Benefit as benefit, Type as type, Charge as Charge, MRN as mrn,
> [GROUP] as gp, SGR as sgr, BENFT.BNFT_DESC AS Description
> FROM Membership INNER JOIN BENFT ON (Charge = BENFT.BCHG) AND (Benefit =
> BENFT.BNFT);
>
> "jonefer" <(E-Mail Removed)> wrote in message
> newsE000F81-B96B-4889-9F37-(E-Mail Removed)...
> > Bill, please help me out. Something as simple as:
> >
> > SELECT Benefit, Type, Charge, MRN, [GROUP], SGR, BENFT.BNFT_DESC
> > FROM Membership INNER JOIN BENFT ON (Charge = BENFT.BCHG) AND (Benefit =
> > BENFT.BNFT);
> >
> > ..should STILL be simple in ADO.NET. Perhaps you think I am asking for
> > something more difficult?
> >
> > It's pretty trivial in Access: pull two tables in, connect the two related
> > fields:
> >
> > Yet, I've spent two days reading and looking at different posts and sites.
> > If ADO.NET is really supposed to help make working with databases simpler,
> > I
> > haven't been convinced yet. I'm talking about adding one field from
> > another
> > table to a dataset.
> >
> > Could you or someone just give me the steps? Because I can't search
> > anymore
> > sites in google to find the answer to this question. I'll read more about
> > it
> > after I digest how to do something so simple.
> >
> >
> > "W.G. Ryan - MVP" wrote:
> >
> >> Jonefer: Have you considered using DataSet.Merge? This would entail two
> >> datasets (so you'd have to move/copy the datatable) but I think it'd give
> >> you what you wanted.
> >> "jonefer" <(E-Mail Removed)> wrote in message
> >> news:855BAAC2-0C12-4FAE-8BE6-(E-Mail Removed)...
> >> > So far the dataset just shows
> >> > Type, Benefit, Change
> >> >
> >> > I want it to show
> >> > Type, Benefit, Change, Description
> >> >
> >> > This should be a pretty elementary question - and I've spent 2 days on
> >> > it
> >> > already.
> >> > I just want to add one field from another table into my dataset, should
> >> > be
> >> > easy, but maybe it's the way it is related that is making it so
> >> > difficult
> >> > (there are no totally unique fields in either table, so it needs a
> >> > multi-join)
> >> >
> >> > I have 2 tables in the dataset already:
> >> > Membership
> >> > BENFT
> >> >
> >> > To get the Desc Field from the BENFT table, I need to relate 2 fields
> >> > to
> >> > Membership
> >> > Membership.Benefit = BENFT.BNFT
> >> > Membership.Change = BENFT.BCHG
> >> >
> >> >
> >> > 'This is what I tried so far, but it's not working
> >> > daBenefits.Fill(DsBenefits1, "Membership")
> >> >
> >> > Dim relBenefit As New DataRelation("relBen",
> >> > DsBenefits1.Tables(0).Columns("Benefit"),
> >> > DsBenefits1.Tables(1).Columns("BNFT"))
> >> > Dim relBenChg As New DataRelation("relChg",
> >> > DsBenefits1.Tables(0).Columns("Change"),
> >> > DsBenefits1.Tables(1).Columns("BCHG"))
> >> >
> >> > DsBenefits1.Relations.Add(relBenefit)
> >> > DsBenefits1.Relations.Add(relBenChg)
> >> >
> >> >
> >> > daBenefitDesc.Fill(DsBenefits1, "BENFT")
> >> >
> >> >
> >> >
> >> > 'DGMembers is the DataGrid
> >> > DGBenefits.DataSource =
> >> > DsBenefits1.Tables("Membership").DefaultView
> >> > DGBenefits.DataBind()
> >> >
> >> > Thank you
> >> >
> >> > Note: Membership is actually a union that I have filled for each piece
> >> > into
> >> > the dsBenefits1
> >> >
> >> >
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      29th Dec 2005
Jonefer,

Did I show you this (simple) sample already?

http://www.vb-tips.com/default.aspx?...3-8a9529b2b38b

I hope this helps,

Cor


 
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
Combining Fields From 2 Tables To Sort Data =?Utf-8?B?TGF1cmVu?= Microsoft Access VBA Modules 1 19th Sep 2007 09:41 PM
Merging two tables in Dataset? I only want to get the matching info based on the two key fields mike11d11 Microsoft VB .NET 8 9th Dec 2006 02:23 AM
Re: Combining identical fields from tables in a query Tom Ellison Microsoft Access Queries 0 17th Aug 2004 10:11 PM
Combining data from 2 tables where the fields are different =?Utf-8?B?TmFuY3k=?= Microsoft Access 1 5th Apr 2004 07:07 PM
Combining two fields from two tables =?Utf-8?B?Um9iIFNwYXJrcw==?= Microsoft Access Forms 1 28th Mar 2004 05:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:35 PM.