none
Use Temporary Table in Report Writer RRS feed

  • Question

  • The basic problem is to create a report of randomly selected rows. My code looks like this currently.

        private void button1_Click(object sender, EventArgs e)
        {
            //Get constants for random calcuations
            DataSetTableAdapters.ConstantsTableAdapter T1 = new DataSetTableAdapters.ConstantsTableAdapter();
            DataTable R1 = T1.GetDataByCode(Quarters.Text);

            if ( R1.Rows.Count > 0 )
            {
                    
                DateTime D1 = (DateTime)R1.Rows[0]["Date1"];    //Start of date range
                DateTime D2 = (DateTime)R1.Rows[0]["Date2"];    //End of date range
                Decimal SE = (Decimal)R1.Rows[0]["Factor"];     //Factor use for calculating starting row

                //Get all rows eligible for selection
                DataSetTableAdapters.DataTableAdapter T2 = new DataSetTableAdapters.DataTableAdapter();
                DataTable R2 = T2.GetDataForSelection(D1, D2);

                int LM = R2.Rows.Count;         //Total number of rows      
                int A1 = (int)(LM * SE);            //Starting Record
                int SS = (int)Spinner1.Value;   //Sample Size
                int A2 = (int)(LM / SS);             //Interval
                int A3 = 1;                               //Order selected
                int I = 0;                                 //Index for sample size
                int J = A1;                               //Index of record for sample

                int[] Rlist = new int[SS];          //Array to hold rows for sample
                      
                //Select rows for sample
                for( I=0; I<SS; I++ )
                {
                    Rlist[I] = J;
                    if (J + A2 > LM)
                    { J += A2 - LM; }
                    else
                    { J += A2; }
                }

                //Mark records to be used
                for ( I=0; I<SS; I++ )
                {
                    J = Rlist[I];
                    DataRow cRow = R2.Rows[J];
                    cRow.SetField("Mark","S");
                    cRow.SetField("Obs1", A3);
                    cRow.AcceptChanges();
                    A3++;
                }
                //Print Report

            }

    This seems to be doing what I want. The results I am look for is a report of the fields with an "S" from data table R2. R2 is a temporary table, not really part of the database. I would like to bind R2 to the report, and I can't find a way to do that. "Mark" and "Obs1" are not in the database; they are created by the SQL statement when the rows are gathered. So, I could create a result table in the database, which would be only used for this process; or I could add these columns to the data table. I have three possible solutions. The second two seem superfluous to me. So, is there a way to add R2 to the report writer? Which of the other two is better? Or is there another way I haven't seen?

    Thursday, August 14, 2014 1:10 PM

Answers

  • Hello wodders,

     So, is there a way to add R2 to the report writer

    What is the report writer here? Just a class using for output the data you need which is created yourself?

    If you want to generate a filter and change your datatable to what you want, you can consider using DataView to help. Then you can fill your new datatable to the place you need.  http://msdn.microsoft.com/en-us/library/system.data.dataview(v=vs.110).aspx

    Here is its detail:

    "Represents a databindable, customized view of a DataTable for sorting, filtering, searching, editing, and navigation. The DataView does not store data, but instead represents a connected view of its corresponding DataTable. Changes to the DataView’s data will affect the DataTable. Changes to the DataTable’s data will affect all DataViews associated with it."

    If you mean you have no idea about how to fill DataTable to any Report Writter, for example, this one http://msdn.microsoft.com/en-us/library/bb955081.aspx

    I'm afraid you have to consult this question to the specific forum about Report Writter, they may share you what kind of "datasource" they required. Maybe they are not using WinForm datatable but have a specific view.

    Regards,



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, August 15, 2014 5:29 AM