Solved

TableAdapter in Web Report Programmatically

Posted on 2014-02-11
10
52 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 500 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 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