?
Solved

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

Posted on 2006-04-20
8
Medium Priority
?
264 Views
Last Modified: 2010-04-23
I'm new at using VB.net 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 = _
            txtNDC.Text()

        End With

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

        Catch ex As Exception

            MessageBox.Show(ex.ToString)

        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

0
Comment
Question by:dlubonski
  • 5
  • 3
8 Comments
 
LVL 6

Accepted Solution

by:
JRossi1 earned 2000 total points
ID: 16500566
A differenct approach:  Consider this:  after creating your dataset, create an XML file based on your database:

VphDrugs.WriteXml("C:\CrystalReports\CrystalReport.xml")

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...

0
 
LVL 6

Expert Comment

by:JRossi1
ID: 16500577
correction:  I meant dataset NOT database.
0
 

Author Comment

by:dlubonski
ID: 16507402
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?
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
LVL 6

Expert Comment

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

Author Comment

by:dlubonski
ID: 16507711
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?
0
 
LVL 6

Expert Comment

by:JRossi1
ID: 16507757
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.
0
 

Author Comment

by:dlubonski
ID: 16507853
Can you make a suggestion on the correct way to update the xml file or point me in the right direction?
0
 
LVL 6

Expert Comment

by:JRossi1
ID: 16507914
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
ds.WriteXml("C:\\CustTableDt.xml")

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:  http://www.vbdotnetheaven.com/Code/Jul2003/2120.asp
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…

599 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