Solved

TableAdapter in Web Report Programmatically

Posted on 2014-02-11
10
62 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

730 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