creating and populating a crystal report using a dataset and text boxes

Posted on 2006-04-20
Last Modified: 2010-04-23
I'm new at using and I have a form that clears and fills a dataset upon a change in text in a  text box on my form. I'd like to print a crystal report after clicking on the print command button. I'm using visual studio 2002 and the crystal reports that came with it.  I've reviewed quite a few previously posted solutions and have become more confused with the different approaches. I've attached the database connection, the data adapter and the dataset to the form and placed this code in the "txtNDC_TextChanged" for the text box

' Get the Parameter object and Set value
        With SqlDataDrugVw.SelectCommand.Parameters
            .Item("@ndcparam").Value = _

        End With

        ' Clear the dataset
        ' Load the dataset using the parameter value
            SqlDataDrugVw.Fill(VphDrugs, "vphdrugs")

        Catch ex As Exception


        End Try

It fills the dataset  as I have two other objects displaying information from the datset after it updates.
Now generally a user will enter information into two other text boxes and hit print.

When they hit print I'd like the report to automatically print at the printer, without the user visibly having to look at it.

I've reviewed a link to a solution "vbnet_win_pass_dataset_main_sub" and couldn't figure out how he created the report without an actual connection through the designer. Although the solution works fine and does what it's supposed to when I run it.

Thanks in advance

Question by:dlubonski
    LVL 6

    Accepted Solution

    A differenct approach:  Consider this:  after creating your dataset, create an XML file based on your database:


    Then you can use the Crystal Report Wizard to point to the XML file to create your report.  Each time the dataset is created, the XML file is updated and so will the report.

    Hope this helps...

    LVL 6

    Expert Comment

    correction:  I meant dataset NOT database.

    Author Comment

    That does allow me to report the data initially in the dataset but doesn't capture the two text fields where the end user enters additional input. I've added the two fields to the dataset so the attributes appear in the XML file when created and can be part of the report, but how do i update the XML just before the report prints?
    LVL 6

    Expert Comment

    When the user clicks on the print button, just write the DataSet to the XML file again:  VphDrugs.WriteXml("C:\CrystalReports\CrystalReport.xml")

    Author Comment

    Let me clarify the whole process, so I'm not asking the wrong question.

    1) The end user scans a barcode and the datset is created based upon the information tied to it.
    2) The end user populates an expiration date of the product into a text field.
    3) The end user populates a mfg lot number based on the manufacturing run.
    4) The end user prints a label / report to be used later so the physical product doesn't have to go through the workflow.

    So I have a dataset created prior to the manual entry of the expiration date and lot number.

    Should I update the dataset and then write out the xml file or

    Should I write out the xml file and then update the elements/nodes when the user hits print just before the report prints?
    LVL 6

    Expert Comment

    If the user doesn't need to see the data they manually enter into the text boxes on-screen, then create/update the xml file when the user clicks the print button.

    Author Comment

    Can you make a suggestion on the correct way to update the xml file or point me in the right direction?
    LVL 6

    Expert Comment

    Here is sample code to write to an XML file:

    ' create a connection string
    Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Northwind.mdb"
    Dim myConnection As OleDbConnection = New OleDbConnection()
    myConnection.ConnectionString = connString
    ' create a data adapter
    Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Customers", myConnection)
    ' create a new dataset
    Dim ds As DataSet = New DataSet()
    ' fill dataset
    da.Fill(ds, "myTable")
    ' write dataset contents to an xml file by calling WriteXml method

    If the XML file already exists the 'writeXml' method will overwrite the file, hence updating it.

    Take a look at this web site.  It contains good information regarding this topic:

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now