如何将sql值传递给Crystal Report参数?我在这里停留了大约一周。请帮助我,谢谢大家。
Dim header As New SqlCommand("SELECT SalesOrder.salesorder_id, SalesOrder.sales_code, Delivery.driver_code, SalesOrder.invoice_dt, Delivery.remark, SalesOrder.customer_icno, Delivery.c_name, Delivery.c_hpno, Delivery.address FROM SalesOrder,Delivery WHERE SalesOrder.salesorder_id = Delivery.salesorder_id AND SalesOrder.salesorder_id=" & checkInvoiceReceiptSalesOrderNo.Text, conn)
Using readerObj As SqlClient.SqlDataReader = header.ExecuteReader
While readerObj.Read
Dim paramFields As New ParameterFields()
Dim paramField As New ParameterField()
Dim discreteVal As New ParameterDiscreteValue()
paramField.ParameterFieldName = "son"
Dim str As String
str = readerObj("salesorder_id").ToString()
discreteVal.Value = str
paramField.CurrentValues.Add(discreteVal)
paramFields.Add(paramField)
End While
End Using
答案 0 :(得分:0)
您此代码。您可以传递参数值。在ParameterDiscreteValue.Value = "Your Parameter Value"
处设置值,在ParameterFieldDefinition = ParameterFieldDefinitions("Parameter Name of Crystal Report")
处设置参数名
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim reportViewer As ReportViewer = New ReportViewer()
Dim cryRpt As ReportDocument = New ReportDocument()
cryRpt = New CrystalReport1()
Dim ParameterFieldDefinitions As ParameterFieldDefinitions
Dim ParameterFieldDefinition As ParameterFieldDefinition
Dim ParameterValues As ParameterValues = New ParameterValues()
Dim ParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
ParameterDiscreteValue.Value = "Your Parameter Value"
ParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
ParameterFieldDefinition = ParameterFieldDefinitions("Parameter Name of Crystal Report")
ParameterValues = ParameterFieldDefinition.CurrentValues
ParameterValues.Clear()
ParameterValues.Add(ParameterDiscreteValue)
ParameterFieldDefinition.ApplyCurrentValues(ParameterValues)
reportViewer.crystalReportViewer1.ReportSource = cryRpt
reportViewer.crystalReportViewer1.Refresh()
reportViewer.ShowDialog()
End Sub