none
All of the table records returned to the report RRS feed

  • Question

  • All of the table records returned to the report

    First of all it’s my first time trying to create my reports using MS Report.RDLC and the report viewer control. I used to create them using crystal reports.

    My problem now is when I fill the dataset all of the table records returned although I used a where clause to return only the needed rows.

    I debug the following line of code and I found out that only the required records returned

    Dim Rows as integer = DataAdapter.Fill(Dataset)

    But when the report show up all of the table records appears on the report.

    Please I need your help.

    I don’t know why it’s behaving this way and how I can control it?

     Private Sub LoadData()
    
      Dim oCon As New System.Data.SqlClient.SqlConnection(GetConnectionString)
    
      Dim sb As New System.Text.StringBuilder
    
    
    
      Try
    
       sb.AppendFormat("{0}{1}", "SELECT ", Environment.NewLine)
    
       sb.AppendFormat("{0}{1}", "AppointmentId, ", Environment.NewLine)
    
       sb.AppendFormat("{0}{1}", "AppointmentDate, ", Environment.NewLine)
    
       sb.AppendFormat("{0}{1}", "BegTime, ", Environment.NewLine)
    
       sb.AppendFormat("{0}{1}", "EndTime ", Environment.NewLine)
    
       sb.AppendFormat("{0}{1}", "FROM CMDB.Appointments.Appointment ", Environment.NewLine)
    
       sb.AppendFormat("{0}{1}", "WHERE AppointmentDate = " & "'" & Me.datSelectedDate.Value.ToShortDateString & "'", Environment.NewLine)
    
       
    
       Dim Adapter As New System.Data.SqlClient.SqlDataAdapter(sb.ToString, oCon)
    
    
    
       Dim ds As New AppointmentDatset
    
       Dim intRows As Integer = Adapter.Fill(ds)
    
    
    
       MsgBox(intRows.ToString)
    
      Catch ex As Exception
    
       Dim strEx As String = ex.Message
    
      End Try
    
     End Sub
    
    
    
     Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
    
      Call LoadData()
    
      Me.AppointmentsTableAdapter.Fill(Me.AppointmentDatset.Appointments)
    
      Me.ReportViewer.RefreshReport()
    
     End Sub
    Monday, August 23, 2010 10:11 PM

Answers

  • Hi Sami2020,

    Sorry for my mistake in my first reply.

    The code should be:
    Me.ReportViewer.DataSources.Add(New ReportDataSource("Dataset Name", DirectCast(Me.Dataset.Table, DataTable)))

    Thanks,
    Jin Chen


    Jin Chen - MSFT
    • Marked as answer by Sami2020 Sunday, August 29, 2010 7:45 PM
    Friday, August 27, 2010 1:48 AM
  • The error disappeared but no records show up in the report

    Me.ReportViewer.LocalReport.DataSources.Clear()
    Me.ReportViewer.LocalReport.DataSources.Add(New ReportDataSource("Appointments", ds.Tables("Appointments")))
    Thanks
    • Marked as answer by Sami2020 Sunday, August 29, 2010 7:46 PM
    Saturday, August 28, 2010 12:06 AM

All replies

  • Hi Sami2020,

    The issue should be due to that, there is a default dataset assigned to the report, and the default dataset has all records.

    To fix the issue, please use the following code(C#):

    this.reportViewer1.LocalReport.DataSources.Clear();
    this.reportViewer1.LocalReport.DataSources.Add("<Dataset name>", ds);
    

    These codes will remove the original datasets, and then assgine the new dataset we created to the report.

    If there is anything unclear, please feel free to ask.

    Thanks,
    Jin Chen


    Jin Chen - MSFT
    Tuesday, August 24, 2010 9:50 AM
  • When I convert the C# lines of code to VB as follow

    Me.ReportViewer.LocalReport.DataSources.Clear()
    Me.ReportViewer.LocalReport.DataSources.Add("Appointment", ds)

    I get an error on the second line

    Value of type 'String' cannot be converted to 'Microsoft.Reporting.WinForm.ReportDataSource'

    Tuesday, August 24, 2010 5:08 PM
  • Please I need your help.

    Is it possible that this error is due to my use of VS 2010?

     

    Thursday, August 26, 2010 3:57 PM
  • Hi Sami2020,

    Sorry for my mistake in my first reply.

    The code should be:
    Me.ReportViewer.DataSources.Add(New ReportDataSource("Dataset Name", DirectCast(Me.Dataset.Table, DataTable)))

    Thanks,
    Jin Chen


    Jin Chen - MSFT
    • Marked as answer by Sami2020 Sunday, August 29, 2010 7:45 PM
    Friday, August 27, 2010 1:48 AM
  • The error disappeared but no records show up in the report

    Me.ReportViewer.LocalReport.DataSources.Clear()
    Me.ReportViewer.LocalReport.DataSources.Add(New ReportDataSource("Appointments", ds.Tables("Appointments")))
    Thanks
    • Marked as answer by Sami2020 Sunday, August 29, 2010 7:46 PM
    Saturday, August 28, 2010 12:06 AM
  • Thank you for the help my problem is resolved. There were no records displayed on the report because of my mastic in the SQL statement.

    Sunday, August 29, 2010 7:48 PM