Link to home
Avatar of Donnie4572
Donnie4572Flag for United States of America

asked on

Filter With Dataview

Hi,
I'm tring to get a simple report added to my web app (VS.NET VB.NET)
I need to filter the data in the report against end user criteria entered at runtime.

Example:
User opens page...on the page is a  couple of textboxes
user enters "start" date into textbox1
user enters "end" date into textbox2

Then report is launched with only the data from within the range of dates.

I was trying to do something like this. (But the crReportDocument.SetDataSource(dv)
 for the report won't accept a daview. (I got error logon failed))

Please help


       da.Fill(mydataset, "mytable")
        Dim dv As New DataView
        dv = mydataset.Tables.Item(0).DefaultView
        dv.RowFilter = "mydate > 11/01/2004"
        dv.RowFilter = "mydate < 12/01/2004"
        crReportDocument.SetDataSource(dv)
        CrystalReportViewer1.ReportSource = crReportDocument

Thank You,
Donnie
       
Avatar of kdubravko
kdubravko

Hello Donnie4572,
I have adapted a code snippet that should do the trick:

      da.Fill(mydataset, "mytable")
        Dim dv As New DataView
        dv = mydataset.Tables.Item(0).DefaultView
        dv.RowFilter = "mydate > 11/01/2004"
        dv.RowFilter = "mydate < 12/01/2004"

      Dim MyDataSet As New DataSet

      MyDataSet.Merge(dv.Table.Clone, False, MissingSchemaAction.Add)

      Try
            For Each dr As DataRowView In dv
                  Dim mydatarow = MyDataSet.Tables(0).NewRow
                  mydatarow.ItemArray = dr.Row.ItemArray
                  MyDataSet.Tables(0).Rows.Add(mydatarow)
            Next
      Catch ex As Exception
            MsgBox(e.ToString())
      End Try

        crReportDocument.SetDataSource(MyDataSet)
        CrystalReportViewer1.ReportSource = crReportDocument

Hope it helps!
ASKER CERTIFIED SOLUTION
Avatar of kdubravko
kdubravko

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Donnie4572

ASKER

kdubravko Thank You for your help!
This is working.
Thanks again for sharing.

Donnie
Glad I could help!