问题描述
我在Visual Studio中有一个CrystalReport,每个表的列都带有参数.如果我从数据库文件中获取数据,则工作正常,但是如果我尝试从codebehind传递参数值,则仅显示表的1行.即使我循环数据集,也仅显示最后一行.如何显示所有行?
以下是我的代码示例;
昏暗的cmd作为Sqlcommand
昏暗的DA作为新的SqldataAdapter
将Dim DS用作新数据集
昏暗的新SqlConnection(WebConfigurationManager.ConnectionStrings("MyConnection").ToString)
Cmd = New SqlCommand("SELECT Name,Age,Gender FROM MyTable",con)
DA.SelectCommand = Cmd
DA.Fill(DS)
昏暗的RptDocument作为新的ReportDocument
昏暗的RptPath作为字符串= HttpContext.Current.Server.MapPath("MyReport.rpt")
RptDocument.Load(RptPath)
RptDocument.SetDatabaseLogon("UserName","PassWord","DataSource","DataBaseName")
将prmParameterValues昏暗为新的ParameterValues
''创建对象以保存参数值
将prmNameValue调暗为新参数DiscreteValue
Dim prmAgeValue作为新参数DiscreteValue
将prmGenderValue调暗为新参数DiscreteValue
''设置参数的值
对于i As Integer = 0到DS.Tables(0).Rows.Count-1
prmNameValue.Value = DS.Tables(0).Rows(i).Item("Name")
prmParameterValues.Add(prmNameValue)
rptDocument.DataDefinition.ParameterFields("Name").ApplyCurrentValues(prmParameterValues)
prmAgeValue.Value = DS.Tables(0).Rows(i).Item("Age")
prmParameterValues.Add(prmAgeValue)
RptDocument.DataDefinition.ParameterFields("Age").ApplyCurrentValues(prmParameterValues)
prmGenderValue.Value = DS.Tables(0).Rows(i).Item("Gender")
prmParameterValues.Add(prmGenderValue)
RptDocument.DataDefinition.ParameterFields("Gender").ApplyCurrentValues(prmParameterValues)
下一个
CrystalReportViewer1.RefreshReport()
CrystalReportViewer1.ReportSource = RptDocument
谢谢.
祝你今天过得愉快. :)
I have a CrystalReport in Visual Studio with Parameters for each column of a table. If i fetch the datas from database fileds,it works fine But if i try to pass the parameter values from codebehind, then only 1 row of the table gets displayed. Even if i loop the dataset, only the last row gets displayed. How do i display all the rows?
Below is my code sample;
Dim cmd as Sqlcommand
Dim DA as New SqldataAdapter
Dim DS as New DataSet
Dim con As New SqlConnection(WebConfigurationManager.ConnectionStrings("MyConnection").ToString)
Cmd = New SqlCommand("SELECT Name,Age,Gender FROM MyTable", con)
DA.SelectCommand = Cmd
DA.Fill(DS)
Dim RptDocument As New ReportDocument
Dim RptPath As String = HttpContext.Current.Server.MapPath("MyReport.rpt")
RptDocument.Load(RptPath)
RptDocument.SetDatabaseLogon("UserName", "PassWord", "DataSource", "DataBaseName")
Dim prmParameterValues As New ParameterValues
''create object to hold parameter value
Dim prmNameValue As New ParameterDiscreteValue
Dim prmAgeValue As New ParameterDiscreteValue
Dim prmGenderValue As New ParameterDiscreteValue
''set the values of the parameters
For i As Integer = 0 To DS.Tables(0).Rows.Count - 1
prmNameValue.Value = DS.Tables(0).Rows(i).Item("Name")
prmParameterValues.Add(prmNameValue)
rptDocument.DataDefinition.ParameterFields("Name").ApplyCurrentValues(prmParameterValues)
prmAgeValue.Value = DS.Tables(0).Rows(i).Item("Age")
prmParameterValues.Add(prmAgeValue)
RptDocument.DataDefinition.ParameterFields("Age").ApplyCurrentValues(prmParameterValues)
prmGenderValue.Value = DS.Tables(0).Rows(i).Item("Gender")
prmParameterValues.Add(prmGenderValue)
RptDocument.DataDefinition.ParameterFields("Gender").ApplyCurrentValues(prmParameterValues)
Next
CrystalReportViewer1.RefreshReport()
CrystalReportViewer1.ReportSource = RptDocument
Thanks.
Have a nice day. :)
推荐答案
这篇关于[已解决]在Crystalreports中,如何为每列显示具有单个参数的所有表行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!