Hamzah AlAfifi
Hamzah AlAfifi

Reputation: 1

i want to extract or generate xml file when i click on print the invoice in crystal report using vb.net and visual studio 2019

i want to extract or generate xml file when i click on print the invoice in crystal report using vb.net and visual studio 2019

i try it with following code but it break and exception unhandled CrystalDecisions.CrystalReports.Engine.ParameterFieldCurrentValueException: 'Missing parameter values.'

this is my code

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

    Cursor = Cursors.WaitCursor
    Timer1.Enabled = True
    Dim rpt As New rptInvoice56() 'The report you created.


    Dim myConnection As SqlConnection
    Dim MyCommand, MyCommand1 As New SqlCommand()
    Dim myDA, myDA1 As New SqlDataAdapter()

    Dim myDS As New DataSet 'The DataSet you created.
    myConnection = New SqlConnection(cs)
    MyCommand.Connection = myConnection
    MyCommand1.Connection = myConnection
    MyCommand.CommandText = "SELECT Customer.ID, Customer.Name, Customer.Gender, Customer.Address, Customer.City, Customer.State, Customer.ZipCode, Customer.ContactNo, Customer.EmailID, InvoiceInfo.Remarks,Customer.Photo, InvoiceInfo.Inv_ID, InvoiceInfo.InvoiceNo, InvoiceInfo.InvoiceDate, InvoiceInfo.CustomerID , InvoiceInfo.GrandTotal, InvoiceInfo.TotalPaid, InvoiceInfo.Balance, Invoice_Product.IPo_ID, Invoice_Product.InvoiceID, Invoice_Product.ProductID, Invoice_Product.CostPrice, Invoice_Product.SellingPrice, Invoice_Product.Margin,Invoice_Product.Qty, Invoice_Product.Amount, Invoice_Product.DiscountPer, Invoice_Product.Discount, Invoice_Product.VATPer, Invoice_Product.VAT, Invoice_Product.TotalAmount, Invoice_Product.Barcode, Product.PID,Product.ProductCode, Product.ProductName FROM Customer INNER JOIN InvoiceInfo ON Customer.ID = InvoiceInfo.CustomerID INNER JOIN Invoice_Product ON InvoiceInfo.Inv_ID = Invoice_Product.InvoiceID INNER JOIN Product ON Invoice_Product.ProductID = Product.PID where InvoiceInfo.Invoiceno=@d1"
    MyCommand.Parameters.AddWithValue("@d1", txtInvoiceNo.Text)
    MyCommand1.CommandText = "SELECT * from Company"
    MyCommand.CommandType = CommandType.Text
    MyCommand1.CommandType = CommandType.Text
    myDA.SelectCommand = MyCommand
    myDA1.SelectCommand = MyCommand1
    myDA.Fill(myDS, "InvoiceInfo")
    myDA.Fill(myDS, "Invoice_Product")
    myDA.Fill(myDS, "Customer")
    myDA.Fill(myDS, "Product")
    myDA1.Fill(myDS, "Company")
    rpt.SetDataSource(myDS)
    rpt.SetParameterValue("p1", txtCustomerID.Text)
    rpt.SetParameterValue("p2", Today)
    frmReport.CrystalReportViewer1.ReportSource = rpt
    rpt.Load("rptinvoice56.rpt")

    rpt.ExportToDisk(ExportFormatType.PortableDocFormat, "C:/rpttt.xml")

    rpt.Export()
    frmReport.Show()

End Sub

Upvotes: 0

Views: 49

Answers (1)

Haim Katz
Haim Katz

Reputation: 461

I generate my xml from the dataset itself.

    myDS.Relations(0).Nested = True  'if you have any nested relationships
    myDS.WriteXml("myfile.xml")

Upvotes: 0

Related Questions