0

I have 2 Datasets with 1 table (7 cols) in each. Both the tables have different column names, but same structure. I want to join/combine/merge these 2 tables and produce a single table with 7 cols only. I treid with Merge, but that produces 14 cols & doesn't actually join both of them. I searched in this site and others too, but couldn't find any appropriate solution for my case. My code is :

    Private Sub FillMatchToOtstdAdapter()
    Dim sql1 As String = "SELECT DOCMCH.docmch_nAccNo, DOCMCH.docmch_lRefDocId, DOCMCH.docmch_nDocLnNo, DOCMCH.docmch_dAdjustedAmt, DOCMCH.docmch_dAdjustedAmt, DOCHDR.dochdr_nVersionNo, 'D' AS Expr1 FROM TXNTYP INNER JOIN (DOCHDR INNER JOIN DOCMCH ON DOCHDR.dochdr_lDocId = DOCMCH.docmch_lRefDocId) ON TXNTYP.txntyp_sDocTyp = DOCHDR.dochdr_sDocType WHERE (((TXNTYP.txntyp_cDocTypCat)='F') AND ((DOCHDR.dochdr_lDocDt)>=20120630));"
    Dim sql2 As String = "select otstnd_nAccNo, otstnd_lDocId, otstnd_nDocLnNo, otstnd_dOtstndgAmt, otstnd_dDocLnAmt, otstnd_nVersionNo, otstnd_cOtstndgSign from otstnd"

    ' Get Records of Query 1
    ds_otstnd_Adap = New OleDb.OleDbDataAdapter(sql1, connStr)
    ds_otstnd_Adap.Fill(ds_otstnd_Ds)
    ds_otstnd_Dt = ds_otstnd_Ds.Tables(0)

    ' Get Records of Query 2
    Dim adap As New OleDb.OleDbDataAdapter(sql2, connStr)
    Dim ds As New DataSet
    adap.Fill(ds)

    ' Merge both of them
    ds_otstnd_Dt.Merge(ds.Tables(0), False, MissingSchemaAction.Add)
    DataGridView1.DataSource = ds_otstnd_Dt
End Sub

Any idea how do I produce the results in a single table with 7 cols only - just data from 2nd table to be added in 1st table. I was thinking of picking each Row from table2 and just addin table1, but their may be many rows & don't want to go in unnecessary process ifthings can be managed in easier and simple manner.

Any help is highly appreciated.

Thanks

4

1 に答える 1

0

わかった。各テーブルの結果に対して同じ列を作成する両方のクエリに「asCol1」を追加しました。マージの場合、MissingSchemaAction.AddをMissingSchemaAction.Ignoreに置き換えました。

これは私にとってうまくいきました。

于 2012-07-26T08:48:50.000 に答える