Click here to Skip to main content
15,906,625 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to pass parameter in my visual basic reportviewer. I got this code in C# around the web then I translated it into VB.Net. I've got errors when I run it. Can anybody tell me why this happens and the solution??
VB
Private Sub ReportViewerManual_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'dbtutorialDataSet.tbltutorial' table. You can move, or remove it, as needed.
    Me.tbltutorialTableAdapter.Fill(Me.dbtutorialDataSet.tbltutorial)
    Me.ReportViewer1.RefreshReport

    Dim AdapterKu As dbtutorialDataSetTableAdapters.tbltutorialTableAdapter = New dbtutorialDataSetTableAdapters.tbltutorialTableAdapter
    Dim TableKu As dbtutorialDataSet.tbltutorialDataTable = New dbtutorialDataSet.tbltutorialDataTable
    AdapterKu.FillBy(TableKu,"7")
    Dim myDataSource As ReportDataSource = new ReportDataSource("Dataset1",(DataTable)TableKu)'-->Here's the error
    Me.ReportViewer1.LocalReport.DataSources.Clear
    Me.ReportViewer1.LocalReport.DataSources.Add(mydatasource)
    Me.ReportViewer1.LocalReport.Refresh
End Sub
Posted
Comments
walterhevedeich 31-Jul-11 11:08am    
What's the error
Monjurul Habib 31-Jul-11 11:08am    
what is the error?
derodevil 31-Jul-11 13:20pm    
ReportDataSource Error says Object variable or With block variable not set.

1 solution

I'm not sure what the (Datatable) bit is for in that statement:
VB
Dim myDataSource As ReportDataSource = new ReportDataSource("Dataset1",(DataTable)TableKu)'-->Here's the error

does it work if you use this instead?
VB
Dim myDataSource As ReportDataSource = new ReportDataSource("Dataset1",TableKu)


If that doesn't work, here[^] is the MSDN Link for the ReportDataSource Constructor. And here[^] is a walk-through on printing a report that might help.
 
Share this answer
 
Comments
derodevil 3-Aug-11 2:14am    
That doesn't work. Thank you for suggestion.
Kschuler 3-Aug-11 8:46am    
Do you get the same error? If not, what does it say? If you QuickWatch the different variables in the statement that is blowing up, can you see which one isn't set. To QuickWatch, set a breakpoint on the line that blows up, run the app, when it hits the breakpoint highlight the variable, right click, select QuickWatch in the menu.
derodevil 4-Aug-11 7:50am    
I have solved the problem. In fact, it just needs two lines of code.
Me.tbltutorialTableAdapter.FillBy(Me.dbtutorialDataSet.tbltutorial,TextBox1.Text) 'TextBox1.Text is the parameter value.
Me.ReportViewer1.RefreshReport
However, thank you for helping me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900