我正在使用vb.net中的水晶报告,报告显示系统用户信息(用户名,位置,工资),我想使用下拉列表和文本框在运行时过滤报告。 下拉列表选择报告将由其过滤的字段"例如:USerName",以及用于设置过滤字段值的文本框"例如:Eric"
问题是我不知道如何在过滤后用新的数据替换晶体报告旧数据
我是水晶报道的新手,请提供任何帮助。
这是我的代码
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GetData()
End Sub
Protected Sub GetData()
Dim connStr As String = ""
Dim con As SqlConnection = New SqlConnection(connStr)
Dim cmd As SqlCommand = New SqlCommand()
Dim ds As DataSet
Dim adapter As SqlDataAdapter
Try
con.Open()
cmd.CommandText = "GetUsersInfo"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
cmd.ExecuteNonQuery()
ds = New DataSet()
adapter = New SqlDataAdapter(cmd)
adapter.Fill(ds)
Dim rd As New ReportDocument()
rd.Load(Server.MapPath("~/Users.rpt"))
rd.SetDataSource(ds.Tables(0))
CrystalReportViewer1.ReportSource = rd
Catch ex As Exception
ex.Message.ToString()
End Try
End Sub
Protected Sub FilterDdL_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles FilterDdL.SelectedIndexChanged
Dim filterField As String
Dim filterFieldValue As String
filterField = FilterDdL.SelectedItem.Value
filterFieldValue = FilterFieldVal.Text
DataTable1.User_Name = ?filterFieldValue
End Sub