Report Viewer not refreshing when data is changed at runtime RRS feed

  • Question

  • hi all,

    I have a form that processes a set of data and saves it to the sql DB. I have another from which has the reportviewer dock to it. I click on the print button and it shows the data from the process form. My issue is that in order to refresh the data you just entered I have to close the program and open it up again so it can refresh the information and display it on the Report Viewer. I am fairly new with report viewer and tried what I thought would have corrected the problem but still nothing. All the information is being processed correction as I can go to the DB make a query(while the program is running) and see the data I just entered on the process form saved on the db. But while in the same run time I try to go to the form with the Report Viewer, the data is not displayed. Once I close and reopen the program, than I am able to see the saved data on the report viewer page.

    Form 1 for processing has a process button which has this code:

    Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
    Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Larry\Documents\Visual Studio 2010\Projects\" & _
                "DDSPayRoll\DDSPayRoll\DDSPayRoll.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
        Dim constr As String = (" INSERT INTO fedtax " & _
              "(eid, payfrom," & _
              " payto, hrswrkd, hrlyrate, " & _
              "grosstotal, medss, totalbfwh, withholding, " & _
              " grandtotal)" & _
              " values " & _
              " ( @val1, @val2, @Val3," & _
              " @Val4, @Val5, @Val6, @Val7," & _
              " @Val8, @Val9, @Val10) ")
        Dim cmd As New SqlCommand(constr, con)
        'Dim kk = cmd.BeginExecuteNonQuery()
        cmd.Parameters.Add(New SqlParameter("@val1", txtEmpID.Text))
        cmd.Parameters.Add(New SqlParameter("@val2", (Format(dtpFromDate.Text, "short date"))))
        cmd.Parameters.Add(New SqlParameter("@val3", (Format(dtpToDate.Text, "short date"))))
        cmd.Parameters.Add(New SqlParameter("@val4", txtHrsWrkd.Text))
        cmd.Parameters.Add(New SqlParameter("@val5", txtHrRate.Text))
        cmd.Parameters.Add(New SqlParameter("@val6", txtGross.Text))
        cmd.Parameters.Add(New SqlParameter("@val7", txtMedSS.Text))
        cmd.Parameters.Add(New SqlParameter("@val8", txtTotalbfwh.Text))
        cmd.Parameters.Add(New SqlParameter("@val9", txtWithHValue.Text))
        cmd.Parameters.Add(New SqlParameter("@val10", txtGndTotal.Text))
        Dim i As Integer
        i = cmd.ExecuteNonQuery()
        If i > 0 Then
         ' cmd.EndExecuteNonQuery(kk)
         MessageBox.Show("Payroll information Saved!")
         MessageBox.Show("Payroll information failed to save")
        End If
        con = Nothing
       End If
      Catch ex As Exception
       MessageBox.Show("Please fill in all the information. ", "Error")
    End Sub

    At this point the information is saved on the DB. I go to the main page and choose the Report Page. The report page should display the information that I just saved to it.

    The code for the second form Report Viewer page looks something like this:

    Public Class Report_BWk
     Public valpay
     Private Sub Report_BWk_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
     End Sub
     Private Sub Report_BWk_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      'TODO: This line of code loads data into the 'DDSPayRollDataSet.biweekly' table. You can move, or remove it, as needed.
      Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Larry\Documents\Visual Studio 2010\Projects\" & _
          "DDSPayRoll\DDSPayRoll\DDSPayRoll.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
      Dim sqlcmdtext As String = "select payfrom from fedtax group by payfrom"
      Dim cmd As New SqlClient.SqlCommand(sqlcmdtext, conn)
      Dim rdr As SqlClient.SqlDataReader = cmd.ExecuteReader
      If rdr.HasRows Then
       While rdr.Read
       End While
      End If
     End Sub
     Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
      If cboPayPeriod.SelectedItem = Nothing Then
       MessageBox.Show("Please select a Pay Period. ", "Error")
       Exit Sub
      End If
      Dim biwk As New Report_BWk
      Dim value As New Date
      lblPayFrom.Text = cboPayPeriod.Text ' SelectedItem
      ' MessageBox.Show(lblPayFrom.Text)
      value = lblPayFrom.Text
      biwk.valpay = value
      Me.biweeklyTableAdapter.Fill(Me.DDSPayRollDataSet.biweekly, biwk.valpay)
     End Sub
     Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
      Dim main1 As New MainForm
     End Sub
    End Class

    Now the Print button is the one that shows the data once it is pressed. I checked the value and indeed the correct value is being processed as a parameter to the DS on which the report viewer is using. At this point when I choose the date and print, the print just shows the template of the report without any data.

    If I close the the program and open it back up. I can go the the second form which is the Report Viewer, choose on the date again and the data is there.

    My issue is that at the point I hit the Print Button on the second form, after I have processed the data, the information has not yet been updated/ refreshed. How can I refresh

    Me.biweeklyTableAdapter.Fill(Me.DDSPayRollDataSet.biweekly, biwk.valpay) Me.ReportViewer1.RefreshReport()

    so it can show me the data at run time when everythnig is being processed.


    Friday, June 17, 2011 1:59 PM

All replies

  • Bump,


    Can anyone just tell me if it is possible to refresh the Report Viewer when data has been changed? Do you have to refresh the Dataset or what has to be done for the updated data to show during run time.



    Monday, June 20, 2011 3:07 PM