dlubonski
asked on
creating and populating a crystal report using a dataset and text boxes
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.SelectComman d.Paramete rs
.Item("@ndcparam").Value = _
txtNDC.Text()
End With
' Clear the dataset
VphDrugs.Clear()
' Load the dataset using the parameter value
Try
SqlDataDrugVw.Fill(VphDrug s, "vphdrugs")
Catch ex As Exception
MessageBox.Show(ex.ToStrin g)
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_ma in_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
' Get the Parameter object and Set value
With SqlDataDrugVw.SelectComman
.Item("@ndcparam").Value = _
txtNDC.Text()
End With
' Clear the dataset
VphDrugs.Clear()
' Load the dataset using the parameter value
Try
SqlDataDrugVw.Fill(VphDrug
Catch ex As Exception
MessageBox.Show(ex.ToStrin
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_ma
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
correction: I meant dataset NOT database.
ASKER
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?
When the user clicks on the print button, just write the DataSet to the XML file again: VphDrugs.WriteXml("C:\Crys talReports \CrystalRe port.xml")
ASKER
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?
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?
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.
ASKER
Can you make a suggestion on the correct way to update the xml file or point me in the right direction?
Here is sample code to write to an XML file:
' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=C:\\Northwind.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection()
myConnection.ConnectionStr ing = 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:\\CustTable Dt.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
' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OL
Dim myConnection As OleDbConnection = New OleDbConnection()
myConnection.ConnectionStr
' 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:\\CustTable
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