|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Joining two datatables with no primary keyI 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? Use a SQL statement wiht inner join keyword?
-- Show quoteMiha 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? > 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? >> > 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? >>> >> > > You might check out this product:
http://www.queryadataset.com/dataset.aspx I never tried it though. -- Show quoteMiha 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: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? >>> >> > > 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? > > > 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? > > > |
|||||||||||||||||||||||