Joining two datatables with no primary key

  • Thread starter Thread starter Karch
  • Start date Start date
K

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?
 
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 said:
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 said:
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?
 
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

Karch said:
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 said:
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 said:
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?
 
Hi,
also you must ensure that both table names are identical otherwise
MissingSchemaAction.AddWithKey wont work properly
 
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/

Karch said:
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 said:
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 said:
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?
 
Back
Top