如何使用 vb.net 将 sql 值设置为水晶报表参数
Posted
技术标签:
【中文标题】如何使用 vb.net 将 sql 值设置为水晶报表参数【英文标题】:how to set sql value to crystal report parameter using vb.net 【发布时间】:2018-07-06 13:34:26 【问题描述】:如何将sql值传递给水晶报表参数?我在这里坚持了大约一个星期。请大家帮帮我。
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
【问题讨论】:
【参考方案1】:你这个代码。您可以传递参数值。在此处设置您的值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
【讨论】:
以上是关于如何使用 vb.net 将 sql 值设置为水晶报表参数的主要内容,如果未能解决你的问题,请参考以下文章
如何为我的项目(VB.Net)中的所有水晶报表设置全局连接字符串
如何将 vb.net 中日期的空值传递给 sql 存储过程?