Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27517

2 arrays, one cup...

$
0
0
Well, not exactly. I have two different collections, filled with different SQL tables:

Code:

Public colNombres, colContadores As New Collection

Try
            con.Open()
            Dim da As New SqlDataAdapter("SELECT DOC01.TIPDOC as abr, CNT00.ID_CNT, " & _
                                        "CNT00.CODEMP, CNT00.CENTRO, CNT00.EJERCI, " & _
                                        "CNT00.TIPDOC, CNT00.NUMSER, CNT00.CONTAD as cnt, " & _
                                        "CNT00.CNTPRE, CNT00.CNTSUF, CNT00.STBLOQ " & _
                                        "FROM CNT00 INNER JOIN DOC01 ON CNT00.TIPDOC = " & _
                                        "DOC01.TIPDOC WHERE CNT00.CENTRO = '" & sCentro & "'" & _
                                        "AND CNT00.EJERCI = '" & sAño & "' AND CNT00.CODEMP = '" & _
                                        sCodEmp & "'", con)
            Dim dt As New DataTable
            Dim oCB As SqlCommandBuilder = New SqlCommandBuilder(da)

            dst = New DataSet
            bdsContad.DataSource = dst
            da.Fill(dst, "abr")

            For Each dtRow As DataRow In dst.Tables(0).Rows
                Dim dtNombre As String = dtRow.Item("abr").ToString
                colNombres.Add(CObj(dtNombre))
            Next

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            con.Close()
        End Try

The second one:
Code:

Try
            con.Open()
            Dim da As New SqlDataAdapter("SELECT DOC01.NOMBRE AS Nom, CNT00.ID_CNT, " & _
                                        "CNT00.CODEMP, CNT00.CENTRO, CNT00.EJERCI, " & _
                                        "CNT00.TIPDOC, CNT00.NUMSER, CNT00.CONTAD as cnt, " & _
                                        "CNT00.CNTPRE, CNT00.CNTSUF, CNT00.STBLOQ " & _
                                        "FROM CNT00 INNER JOIN DOC01 ON CNT00.TIPDOC = " & _
                                        "DOC01.TIPDOC WHERE CNT00.CENTRO = '" & sCentro & "'" & _
                                        "AND CNT00.EJERCI = '" & sAño & "' AND CNT00.CODEMP = '" & _
                                        sCodEmp & "'", con)
            Dim dt As New DataTable
            Dim oCB As SqlCommandBuilder = New SqlCommandBuilder(da)

            dst = New DataSet
            bdsContad.DataSource = dst
            da.Fill(dst, "cnt")
         
            Next

In this case, both arrays have the same lenght according to "where" statements. And their length always should match. I need to record each pair of values in a single row. Something like this:

INSERT INTO [table] (column1, column2) values ('collection1(1)', 'collection2(1)')
INSERT INTO [table] (column1, column2) values ('collection1(2)', 'collection2(2)')
INSERT INTO [table] (column1, column2) values ('collection1(3)', 'collection2(3)')

And so until the end. Considering my short knowledge, and implying I don't know to refer an item when it's collection is filled with an SQL Query, I've tried some ideas (creating a new datatable, insert the first collection and trying to update it after with the second...) but no one worked.

Any idea?

Viewing all articles
Browse latest Browse all 27517

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>