Solved

TableAdapter in Web Report Programmatically

Posted on 2014-02-11
10
37 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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!
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now