none
ReportViewer display problem [VS 2005] RRS feed

  • Question

  • Hi

    I can created a reportviewer and a dropdownlist. By selecting the value in the dropdownlist, the report will only generate the report based on the column. Eg. (I select line 1 from the droplist, report will generate details with line 1 only)

    However, when i select another value and want to generate new data, the old data still stays at the reportviewer. I am wondering what is wrong.

    Here is my code for the button:
      Code Snippet
        Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
                sqlConn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings.Item("ProdTrackingConnectionString").ConnectionString

                If Label1.Text = "Line" Then
                    SqlStr = "SELECT * FROM OutputRepairDetails WHERE Line =  '" & DropDownList1.Text & "'"
                    LastSearchMode = Label1.Text
                    LastSearchStr1 = DropDownList1.Text
                End If

                If Label1.Text = "Lot No" Then
                    SqlStr = "SELECT * FROM OutputRepairDetails WHERE LotNum = '" & DropDownList1.Text & "'"
                    LastSearchMode = Label1.Text
                    LastSearchStr1 = DropDownList1.Text
                End If

                If Label1.Text = "Model" Then
                    SqlStr = "SELECT * FROM OutputRepairDetails WHERE Model =  '" & DropDownList1.SelectedItem.Text & "'"
                    LastSearchMode = Label1.Text
                    LastSearchStr1 = DropDownList1.SelectedItem.Text
                End If


                sqlConn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings.Item("ProdTrackingConnectionString").ConnectionString

                Dim reader As SqlDataReader
                Dim dsReport As New dsSearch



                'Populate Search Result REPORTVIEWER

                SqlComm.CommandText = SqlStr
                SqlComm.Connection = sqlConn
                sqlConn.Open()

                reader = SqlComm.ExecuteReader

                If reader.Read() Then
                    Try

                        dsReport.Tables(0).Load(reader)


                        rpvSearch.LocalReport.ReportEmbeddedResource = "eff report.Search.rdlc"

                        Dim rds As New ReportDataSource
                        rds.Name = "dsSearch_OutPutRepairDetails"
                        rds.Value = dsReport.Tables(0)
                        rpvSearch.LocalReport.DataSources.Add(rds)

                        reader.Close()
                        sqlConn.Close()

                        rpvSearch.LocalReport.Refresh()

                        lblNoRecords.Visible = False
                        rpvSearch.Visible = True


                    Catch ex As Exception
                        lblError.Text = ex.Message
                    Finally
                        If sqlConn.State = ConnectionState.Open Then
                            sqlConn.Close()
                        End If
                    End Try

                    Else
                lblNoRecords.Visible = True
                rpvSearch.Visible = False
                    End If
            End Sub

       Can anyone help?

    Tuesday, March 27, 2007 8:22 AM

Answers

  • Code Snippet

    rpvSearch.Reset();



    Should solve your problem, call this before you start passing any details into the reportViewer.
    Tuesday, March 27, 2007 11:41 AM

All replies

  • Code Snippet

    rpvSearch.Reset();



    Should solve your problem, call this before you start passing any details into the reportViewer.
    Tuesday, March 27, 2007 11:41 AM
  •  

    Hi,

     

    I think that the problem is that your report adds a dataSource every time the btnSearch_Click is called.

     

    Try calling the method

     

     rpvSearch.LocalReport.DataSources.Clear()

     

    before you add your dataSource to the report.

     

    Hope this might help.

     

     

    Friday, March 30, 2007 4:03 PM