borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (From Flexgrid to CR)Next Topic (mdb password) New Topic New Poll Post Reply
AndreaVB Forum : Reporting tools : Multiple ADO Commands or Query
Poster Message
Aeric
Level: Sage


Registered: 16-06-2003
Posts: 53

icon Multiple ADO Commands or Query

I want to display a Client Statement using VB6 and Crystal Reports 8.5 with SQL Server 2000 database. I combine the invoice data from table tblInvoice with client details from table tblClient.

Private Sub Form_Load()
    Dim strSQL As String
    Dim Cmd As ADODB.Command
    Dim conn As ADODB.Connection
        
    Set Cmd = New ADODB.Command
    Set conn = New ADODB.Connection
    
    conn.Open "Provider=SQLOLEDB.1;Password=" & gstrUserPass & ";Persist Security Info=True;User ID=" & gstrUserName & ";Initial Catalog=" & gstrDatabaseName & ";Data Source=" & gstrServerName

    Cmd.ActiveConnection = conn
    
    strSQL = "SELECT ClientID, Name1, Address," & _
          " InvoiceNum, InvoiceAmount" & _
          " FROM [tblInvoice] JOIN [tblClient] ON tblInvoice].ClientID = tblClient.ClientID" & _
                    " WHERE ClientID BETWEEN '" & strFromID & "' AND '" & strToID & _
                    "' ORDER BY ClientID"
        
    Cmd.CommandText = strSQL
    Cmd.CommandType = adCmdText
    Report.Database.AddADOCommand conn, Cmd
    Report.AutoSetUnboundFieldSource crBMTName
    
    Report.ClientID.SetUnboundFieldSource ("{ADO.ClientID}")
    Report.ClientName.SetUnboundFieldSource ("{ADO.ClientName1}")
    Report.ClientAddress.SetUnboundFieldSource ("{ADO.Address}")
    Report.InvoiceNo.SetUnboundFieldSource ("{ADO.InvoiceNum}")
    Report.Total.SetUnboundFieldSource ("{ADO.InvoiceAmount}")
    
    CRViewer1.ReportSource = Report
    CRViewer1.ViewReport
    CRViewer1.Zoom 1
    
    conn.Close
    Set conn = Nothing
End Sub


Can I use 2 ADO commands in the following line?
Report.Database.AddADOCommand conn, Cmd


One ADO command to get the Client details and another for the Invoice details so i only get the Client details once for each Client ID.

The Statement report i want will look like this:

ClientID1
ClientName1
ClientAddress1

InvoiceNo1     Amount1
InvoiceNo2     Amount2
InvoiceNo3     Amount3
...                  ...


ClientID2
ClientName2
ClientAddress2

InvoiceNo1     Amount1
InvoiceNo2     Amount2
...                  ...

I hope by using 2 ADO, the report generating speed will improved.

23-06-2006 at 04:32 AM
View Profile Send Email to User Show All Posts Visit Homepage ICQ | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: Multiple ADO Commands or Query

Hello. I'm not deep into ADO Command object, but I'm afraid you can't. Yet, I wonder if you couldn't group the two SQL instructions into one single ADO Command. I often pass two SQL instructions together to get a recordset, like in here.
Hope it helps

____________________________
Real Programmer can count up to 1024 on his fingers

23-06-2006 at 08:40 AM
View Profile Send Email to User Show All Posts | Quote Reply
Aeric
Level: Sage


Registered: 16-06-2003
Posts: 53
icon Re: Multiple ADO Commands or Query

Well, i come across a feature call Subreport. I think what i want can be accomplished by using this feature. Since i never use subreport before, i think i will do a research on it. Thanks for reply.

23-06-2006 at 08:54 AM
View Profile Send Email to User Show All Posts Visit Homepage ICQ | Quote Reply
AndreaVB Forum : Reporting tools : Multiple ADO Commands or Query
Previous Topic (From Flexgrid to CR)Next Topic (mdb password) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder