Home All Groups Group Topic Archive Search About

Joining two datatables with no primary key

Author
18 Feb 2007 9:08 PM
Karch
I have two datatables that share two columns which could be thought of as
the primary key. There are additional columns NOT shared between the two
tables. I need to merge the two tables together where Table1.ColumnA =
Table2.ColumnA and Table1.ColumnB = Table2.ColumnB. What is the best way to
do this?

Author
18 Feb 2007 9:46 PM
Miha Markic [MVP C#]
Use a SQL statement wiht inner join keyword?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Karch" <nospam@absotutely.com> wrote in message
news:%23Sb9FE6UHHA.5060@TK2MSFTNGP06.phx.gbl...
>I have two datatables that share two columns which could be thought of as
>the primary key. There are additional columns NOT shared between the two
>tables. I need to merge the two tables together where Table1.ColumnA =
>Table2.ColumnA and Table1.ColumnB = Table2.ColumnB. What is the best way to
>do this?
>
Author
19 Feb 2007 2:45 AM
Karch
I should have mentioned that these are data tables in a dataset. I know how
to write a SQL statement with inner join. These are existing datatables and
I need to merge them, so I'm looking for the best way given the constraints
below. The JoinView sample from MS seems like overkill, so I was hoping
there was some elegant way to convince the dataset or datatable that a merge
could happen. As I said, though, their is no primary key column, only the
composite of ColumnA and ColumnB.

Thanks!

Show quote
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:3F93D8A5-EFC4-4D6E-B21A-B203824EFD86@microsoft.com...
> Use a SQL statement wiht inner join keyword?
>
> --
> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
> RightHand .NET consulting & development www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>
> "Karch" <nospam@absotutely.com> wrote in message
> news:%23Sb9FE6UHHA.5060@TK2MSFTNGP06.phx.gbl...
>>I have two datatables that share two columns which could be thought of as
>>the primary key. There are additional columns NOT shared between the two
>>tables. I need to merge the two tables together where Table1.ColumnA =
>>Table2.ColumnA and Table1.ColumnB = Table2.ColumnB. What is the best way
>>to do this?
>>
>
Author
19 Feb 2007 6:58 AM
Cor Ligthert [MVP]
Karch,

Your question is not to answer, mostly there is no best way and certainly
not in this strange way.

Probably you can use this one.
http://www.vb-tips.com/dbpages.aspx?ID=5fd5a8cf-54dc-4946-a193-8a9529b2b38b

I hope this helps,

Cor

Show quote
"Karch" <nospam@absotutely.com> schreef in bericht
news:euZ96c9UHHA.3500@TK2MSFTNGP05.phx.gbl...
>I should have mentioned that these are data tables in a dataset. I know how
>to write a SQL statement with inner join. These are existing datatables and
>I need to merge them, so I'm looking for the best way given the constraints
>below. The JoinView sample from MS seems like overkill, so I was hoping
>there was some elegant way to convince the dataset or datatable that a
>merge could happen. As I said, though, their is no primary key column, only
>the composite of ColumnA and ColumnB.
>
> Thanks!
>
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> news:3F93D8A5-EFC4-4D6E-B21A-B203824EFD86@microsoft.com...
>> Use a SQL statement wiht inner join keyword?
>>
>> --
>> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
>> RightHand .NET consulting & development www.rthand.com
>> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>>
>> "Karch" <nospam@absotutely.com> wrote in message
>> news:%23Sb9FE6UHHA.5060@TK2MSFTNGP06.phx.gbl...
>>>I have two datatables that share two columns which could be thought of as
>>>the primary key. There are additional columns NOT shared between the two
>>>tables. I need to merge the two tables together where Table1.ColumnA =
>>>Table2.ColumnA and Table1.ColumnB = Table2.ColumnB. What is the best way
>>>to do this?
>>>
>>
>
>
Author
19 Feb 2007 9:10 AM
Miha Markic [MVP C#]
You might check out this product:
http://www.queryadataset.com/dataset.aspx
I never tried it though.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Karch" <nospam@absotutely.com> wrote in message
news:euZ96c9UHHA.3500@TK2MSFTNGP05.phx.gbl...
>I should have mentioned that these are data tables in a dataset. I know how
>to write a SQL statement with inner join. These are existing datatables and
>I need to merge them, so I'm looking for the best way given the constraints
>below. The JoinView sample from MS seems like overkill, so I was hoping
>there was some elegant way to convince the dataset or datatable that a
>merge could happen. As I said, though, their is no primary key column, only
>the composite of ColumnA and ColumnB.
>
> Thanks!
>
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> news:3F93D8A5-EFC4-4D6E-B21A-B203824EFD86@microsoft.com...
>> Use a SQL statement wiht inner join keyword?
>>
>> --
>> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
>> RightHand .NET consulting & development www.rthand.com
>> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>>
>> "Karch" <nospam@absotutely.com> wrote in message
>> news:%23Sb9FE6UHHA.5060@TK2MSFTNGP06.phx.gbl...
>>>I have two datatables that share two columns which could be thought of as
>>>the primary key. There are additional columns NOT shared between the two
>>>tables. I need to merge the two tables together where Table1.ColumnA =
>>>Table2.ColumnA and Table1.ColumnB = Table2.ColumnB. What is the best way
>>>to do this?
>>>
>>
>
>
Author
19 Feb 2007 8:49 AM
Manish Bafna
Hi,
yes you can do it.You need to set MissingSchemaAction.AddWithKey while using
DataSet.Merge.It will work as if you are using inner join between two
tables.You will find following URL useful:
http://msdn2.microsoft.com/en-us/library/aszytsd8(VS.80).aspx

Hope this helps you out.

Thanks and Regards,
Manish Bafna.
MCP and MCTS.

Show quote
"Karch" wrote:

> I have two datatables that share two columns which could be thought of as
> the primary key. There are additional columns NOT shared between the two
> tables. I need to merge the two tables together where Table1.ColumnA =
> Table2.ColumnA and Table1.ColumnB = Table2.ColumnB. What is the best way to
> do this?
>
>
>
Author
19 Feb 2007 9:08 AM
Manish Bafna
Hi,
also you must ensure that both table names are identical otherwise
MissingSchemaAction.AddWithKey wont work properly

Show quote
"Karch" wrote:

> I have two datatables that share two columns which could be thought of as
> the primary key. There are additional columns NOT shared between the two
> tables. I need to merge the two tables together where Table1.ColumnA =
> Table2.ColumnA and Table1.ColumnB = Table2.ColumnB. What is the best way to
> do this?
>
>
>

AddThis Social Bookmark Button