当我使用 vb.net 和 Visual Studio 2019 单击水晶报表中的打印发票时,我想提取或生成 xml 文件
我尝试使用以下代码,但它中断并且异常未处理 CrystalDecisions.CrystalReports.Engine.ParameterFieldCurrentValueException:“缺少参数值。”
这是我的代码
Private Sub Button3_Click(sender As Object, e As EventArgs) 处理 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
我从数据集本身生成 xml。
myDS.Relations(0).Nested = True 'if you have any nested relationships
myDS.WriteXml("myfile.xml")