Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VS2012 report empty when using datasource from code behind

Status
Not open for further replies.

mmy1981

Programmer
Apr 2, 2007
164
BE
Hi,
untill now, I always used Crystal Reports with VS2012, but I'm trying the .rdlc reports now to check it as an alternative.

I would like to fill the report from the code behind, using my own SQL select commands. So, I cannot use the wizard to create and display the report.
However, I guess I can/must use the wizard to create the report (layout, what columns to add, ...).

I'v added a ReportViewer to my windows form, created a new report (Report1.rdlc) and used an SQL connection to fill the data. The report loads with the data.
Now, I used the following code in the form_load event to display the desired records.

Code:
Dim connectiestring As String = My.Settings.ConnectieString
        Dim objConnection As SqlConnection = New SqlConnection(connectiestring)
        Dim objDataSet As DataSet
        Dim objEmployeesAdapater As SqlDataAdapter
        objConnection.Open()
        objDataSet = New DataSet("employees")
        objEmployeesAdapater = New SqlDataAdapter("SELECT * FROM tblwerknemers", objConnection)
        objEmployeesAdapater.Fill(objDataSet, "tblwerknemers")
        objConnection.Close()

        'MsgBox(objDataSet.Tables("tblwerknemers").Rows.Count)

        Dim rds As ReportDataSource = New ReportDataSource("DataSet1", objDataSet.Tables("tblwerknemers"))
        ReportViewer1.LocalReport.DataSources.Add(rds)
        Me.ReportViewer1.RefreshReport()

The report shows the column names, but no data.
If I uncomment the Msgbox line, it says there are several rows. So, I'm sure the datatable is filled with info

Anybody can help me with this one?
 

Try this before you add the new datasource:

ReportViewer1.LocalReport.DataSources.Clear()


You might also try, after setting the datasource, setting the DisplayMode:

ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)

Try different DisplayModes to see what works.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
no luck...
adding the .Clear gives the messages "A data source instance has not been supplied for the data source 'objDataSet' in the report.
Seems normals since I haven't added a data source before this clear method.

If I don't use this code, the column names are shown in the report. The DisplayMode does switch to print or normal layout.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top