Advertisement

03.14.2008 at 11:15PM PDT, ID: 23243725
[x]
Attachment Details

Help with econnect vb.net example

Asked by wmikeh40 in .Net Editors & IDEs, Microsoft Visual Basic.Net, Microsoft Dynamics

Tags: vb.net

Hi,  I am experimenting with econnect and am having problems with the code below.  This code loads two different tables - 1 is the header table and the other is the distribution table.  They are in a 1 to many relationship.  The problem I am getting is that when this code runs the records are being imported but the distribution lines are being duplicated.  For example if I have 3 different distribution lines a,b, and c.  The result I am getting is 3 c's.  I believe it has something to do with the way I am loading the array.  Any help would be appreciated.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
Public Shared Sub main()
 
        Try
 
            Dim recvTrans As New taRMTransaction
            Dim recvDistTrans As New taRMDistribution_ItemsTaRMDistribution
 
            Dim sConnectionString As String
            sConnectionString = "data source=U15257803;initial catalog=TWO;integrated security=SSPI;persist security info=False;packet size=4096"
            Dim ccDocNum As String
            Dim cn As New SqlClient.SqlConnection
            Dim query As String
            cn.ConnectionString = "Data source=U15257803;initial catalog=APPDATA;integrated security=SSPI;persist security info=False;packet size=4096"
 
            query = "Select * from rmTrans"
            'Dim cmd As New Data.SqlClient.SqlCommand(query, cn)
            'Dim dr As SqlClient.SqlDataReader
            Dim NextDocNumberObject As New GetNextDocNumbers
            'dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            Dim da As SqlDataAdapter
            Dim ds As DataSet
            Dim dtrParent As DataRow
            Dim dtrChild As DataRow
 
            da = New SqlDataAdapter(query, cn)
            ds = New DataSet()
            cn.Open()
            da.Fill(ds, "Header")
            da.SelectCommand = New SqlCommand("Select * from rmDist", cn)
            da.Fill(ds, "Dist")
            cn.Dispose()
            ds.Relations.Add("ParentChild", ds.Tables("Header").Columns("id"), ds.Tables("Dist").Columns("id2"))
            For Each dtrParent In ds.Tables("Header").Rows
 
 
                
                With recvTrans
                    .BACHNUMB = dtrParent("BACHNUMB")
                    .BatchCHEKBKID = "UPTOWN TRUST"
                    .DOCAMNT = dtrParent("DOCAMNT")
                    .SLSAMNT = dtrParent("SLSAMNT")
                    .CRCARDDT = dtrParent("DOCDATE")
                    .CRCRDAMT = dtrParent("CRCRDAMT")
                    .CRCRDNAM = dtrParent("CRCRDNAM")
                    .RMDTYPAL = dtrParent("RMDTYPAL")
                    .DOCDATE = dtrParent("DOCDATE")
                    .DOCNUMBR = ""
                    .CUSTNMBR = dtrParent("CUSTNMBR")
                    ccDocNum = NextDocNumberObject.GetNextRMNumber(GetNextDocNumbers.IncrementDecrement.Increment, GetNextDocNumbers.RMPaymentType.RMPayments, sConnectionString)
                    .DCNUMCRD = ccDocNum
                    .CREATEDIST = 0
 
                End With
                Dim distlines(0) As taRMDistribution_ItemsTaRMDistribution
                Dim ln As Long
                ln = 0
 
                For Each dtrChild In dtrParent.GetChildRows("ParentChild")
 
                    With recvDistTrans
                        .CUSTNMBR = dtrParent("CUSTNMBR")
                        .RMDTYPAL = dtrChild("RMDTYPAL")
                        .DOCNUMBR = recvTrans.DOCNUMBR
                        .DISTTYPE = dtrChild("DISTTYPE")
                        .DSTINDX = dtrChild("DSTINDX")
                        .DEBITAMT = dtrChild("DEBITAMT")
                        .CRDTAMNT = dtrChild("CRDTAMNT")
                    End With
 
                    distlines(ln) = recvDistTrans
                    ln = ln + 1
                    ReDim Preserve distlines(ln)
                Next
                Dim rmOrder As New RMTransactionType
                rmOrder.taRMDistribution_Items = distlines
                rmOrder.taRMTransaction = recvTrans
                Dim eConnect As New eConnectType
                ReDim Preserve eConnect.RMTransactionType(0)
                eConnect.RMTransactionType(0) = rmOrder
                'Create a file and stream to use to serialize the XML document to a file
                Dim fs As New FileStream("salesorder.xml", FileMode.Create)
                Dim writer As New XmlTextWriter(fs, New UTF8Encoding)
                Dim salesOrderDocument As String
                Dim eConCall As New Microsoft.Dynamics.GP.eConnect.eConnectMethods
                Dim xmldoc As New Xml.XmlDocument
                'Serialize the XML document to the file
                Dim serializer As New XmlSerializer(GetType(eConnectType))
                serializer.Serialize(writer, eConnect)
                writer.Close()
                xmldoc.Load("SalesOrder.xml")
                salesOrderDocument = xmldoc.OuterXml
                eConCall.eConnect_EntryPoint(sConnectionString, Microsoft.Dynamics.GP.eConnect.EnumTypes.ConnectionStringType.SqlClient, salesOrderDocument, Microsoft.Dynamics.GP.eConnect.EnumTypes.SchemaValidationType.None)
                eConCall.Dispose()
            Next
 
        Catch ex As ApplicationException
            Console.Write(ex.ToString)
        End Try
 
    End Sub
 
End Class
[+][-]03.15.2008 at 07:25AM PDT, ID: 21132605

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .Net Editors & IDEs, Microsoft Visual Basic.Net, Microsoft Dynamics
Tags: vb.net
Sign Up Now!
Solution Provided By: jgv
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628