Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TableAdapter in Web Report Programmatically

Posted on 2014-02-11
10
Medium Priority
?
85 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

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