Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

TableAdapter in Web Report Programmatically

Posted on 2014-02-11
10
Medium Priority
?
91 Views
Last Modified: 2016-08-29
When I run the pageload in attached file I get the error "The Select operation is not supported by ObjectDataSource 'ObjectDataSource1' unless the SelectMethod is specified."

Of course I know why I am getting this but is there no way to set this programmatically?

Please guys only reply if you know the answer definitely please do not send me to reams of websites I can do that myself.


Thanks.
PageLoad.txt
0
Comment
Question by:Paulmc999
  • 3
  • 3
  • 2
10 Comments
 
LVL 25

Expert Comment

by:apeter
ID: 39936647
Try like below. Looks like you are closing the connection early.

protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection MySQL = new SqlConnection();
            MySQL.ConnectionString = ConfigurationManager.ConnectionStrings["BConn"].ConnectionString;

            SqlCommand command = new SqlCommand();
            SqlDataReader drReport;
            DataSet dsReport = new ReceiptPDS();
 
           

            try
            {
                MySQL.Open();
               
                command.CommandType = CommandType.Text;
                command.Connection = MySQL;
                command.CommandText = "Select DateNo AS Date, TCode AS Test, Price FROM PTest";
               

                drReport = command.ExecuteReader();
                dsReport.Tables[0].Load(drReport);

               
                ReportViewer1.LocalReport.ReportPath = "ReceiptPRep1.rdlc";

                ReportDataSource rds = new ReportDataSource();
                rds.Name = "ReceiptPDS_ReceiptPDS";
                rds.Value = dsReport.Tables[0];
               
                ReportViewer1.LocalReport.DataSources.Add(rds);


            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
                if (drReport != Null)
                 {
                            drReport.Close();
                 }


                if (MySQL.State == ConnectionState.Open)
                {
                    MySQL.Close();
                }
            }
        }
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 2000 total points
ID: 39936836
Your code works just fine as is, I actually tried it (with modifications for my database). And your code does not have and does not need any ObjectDataSource anyways. Maybe it was added by some wizard when you were playing with it, but the code that you posted creates and binds programmatically everything needed for the report. The only thing that is missing is dataset ReceiptRDS with the table ReceiptPDS inside, and report template ReceiptPRep1.rdlc.

Even if you used UI rather than code, it's probably easier to add not ObjectDataSource but SQLDataSource.
0
 
LVL 2

Author Comment

by:Paulmc999
ID: 39956369
Sorry for timelapse guys.

@apeter i see your point however i still get same error even when I fix this.

@vadimrapp1 I deleted ObjectDataSource but now it complains it still needs a datasaource. Could you please let me have your files so I can compare to my code?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39956508
here it is

https://filedb.experts-exchange.com/incoming/ee-stuff/8343-vrapp1.rar

open website from file system to see.
0
 
LVL 25

Expert Comment

by:apeter
ID: 39956529
Why you are using data reader and then populating dataset, instead directly get dataset using the command object.
0
 
LVL 2

Author Comment

by:Paulmc999
ID: 39966281
@apeter I am following an example from a book on SSRS in c#. If you have a specific code change suggestion that you have gotten to work please let me have it

@vadimrapp1 I am at a loss as to how to see if your code works, first it seems to be in VS2008 and secondly has no solution file, is it not a web app? I can make changes and convert it etc but really I just want to see it working
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39967186
Ok, I uploaded new sample at https://filedb.experts-exchange.com/incoming/ee-stuff/8343-vrapp1.rarhttps://filedb.experts-exchange.com/incoming/ee-stuff/8346-website.zip


To try it out:
1. download website.zip and extract to folder
2. open visual studio and open website from file system, point it to the folder from #1
3. open code of the webpage and change connection string to connect to your database
4. run it.

But if you are practicing or trying to learn how this plays together, you in fact can have report without a single line of code.

Create new asp.net webform
add report viewer
from smart tag, select "design new report"
go through the wizard, specify connection and your table, move the fields to the right places in the report (page/group/details)
That's all.
0
 
LVL 2

Author Comment

by:Paulmc999
ID: 39967208
Thanks i will try this. No i am not just trying this i am learning how to manipulate the report programmatically not set up through wizard. I'll let you know how i get on. Thanks.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question