Usually never get good answers on this forum but here it goes

  • This seems to be the appropriate thread to post my problem in:

    I'm also trying to bind to a ReportViewer object, however I'm not binding a stored procedure but dynamic sql that selects <dynamic columns> from <dynamic views or tables>

    nice huh? My boss has fallen in love with the front end on Microsoft Dynamics and issued a task for me to develop the same type of front end to our reports (which he likes to call reports but are really just about a hundred views and tables) he expects me to use the ReportViewer object because he loves this thing (I, myself hate it). I am therefore, forced to try to use ReportViewer with absolutely no developed rdl's since all I have is dynamic sql that runs against views or tables. I'm also developing in C# (my boss's favorite, again not mine). Anyway here is my source as it is:

    char[] endlim = { ',' };

    String strItem = String.Empty;

    String sqlStmt = String.Empty;

    int x = 0;

    // Setup Connection string

    cnstr = "server=serverIP;user=mylogin;password=mypassword;"

    + "database=db;";

    // Create a new Sql Connection

    SqlConnection cn = new SqlConnection(cnstr);

    //Create the DataSet

    ds = new DataSet("ds");

    sqlStmt = "Select ";

    //string querystring = "EmployeeReportViewer.aspx?ViewOrTable=" + ReportList.SelectedValue.ToString();

    foreach (ListItem listItem in ColumnListBox.Items)

    {

    if (listItem.Selected)

    {

    strItem = listItem.ToString();

    sqlStmt += strItem + ", ";

    }

    }

    sqlStmt = sqlStmt.Trim();

    sqlStmt = sqlStmt.TrimEnd(endlim);

    sqlStmt += " FROM " + ReportList.SelectedValue.ToString();

    SqlDataAdapter da = new SqlDataAdapter(sqlStmt, cn);

    // Fill the Data Adapter

    da.Fill(ds);

    DsRpt = Microsoft.Reporting.WebForms.ReportDataSource();

    DsRpt.Name = "Test";

    ReportViewer1.LocalReport.DataSources.Clear();

    //ReportViewer1.LocalReport.DataSources.Add(ds);

    }

    How in the h double hockey sticks can I create an RDL on the fly, with no defined columns or ReportDataSource?

    Thanks anybody in advance.

    Dean

  • there's a an project on codeproject.com that has a decent example of how to bind a report to a dynamic dataset; by coincidence it's also in C# as well;

    basically, it gets the datatable, and then dynamically creates the fields based on the datatable.

    take a look a this project and see if you can adapt it to your needs:

    http://www.codeproject.com/KB/reporting-services/DynamicReports.aspx

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Hallelujah!! this looks like its will be of use! thanks a bunch, will let you know how it goes.

  • "Usually never get good answers on this forum but here it goes"

    We're even then. We usually never get good questions on this forum, either. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (9/17/2010)


    "Usually never get good answers on this forum but here it goes"

    We're even then. We usually never get good questions on this forum, either. 😉

    Yep asking the question different ways (as opposed to the same verbiage over and over like other posters) was what got the breakthrough on this one. persistance!

    I looked at his previous posts, and they were along the same theme on Reporting Services and dynamic queries, but the way he asked THIS time made the light bulb come on; I knew I had used a project from codeproject doing exactly that, just had to search to find it;

    Actually i took that project and converted it to VB.net, as that's my programming language of choice.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks guys, I didn't mean to be overly critical of your forum, via the question "I don't usually get good answers ...". This was a cry for help, that would catch the eyes of the good posters.. I'm not fed very good requirements so I'm kinda in the dark about what exactly I'm supposed to do either. That's why my posts sound vague and weird sometimes.

    Sorry guys keep up the good work!!

    Dean

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply