Hi,

How do I pass my variable or textbox data from form to Active Reports class where I prepare my sql string so that I can use my variable in "Where" clause..like select * from personnel where name=' " + textboxName.Text + " ' "; Thanks,
snky

http://www.datadynamics.com/forums/82/ShowForum.aspx


Visit http://www.datadynamics.com/Help/ActiveReports6/arHOWAddParameters.html and expand the topics "To add parameters to a SQL query" and "To add parameters at run time in C#" or "To add parameters at run time in Visual Basic.NET". That should show you how to do exactly what you are asking.

If you have more questions please feel free to use the very active ActiveReports Support forum on our website at http://www.datadynamics.com/forums/82/ShowForum.aspx .

Hope this helps!

Scott Willeke
GrapeCity / Data Dynamics

Just in case people are interestedi this is how I solved it.

private void toolStripButton1_Click(object sender, EventArgs e)
 //Create the report and assign the data source
                        NewActiveReport2 rpt = new NewActiveReport2(dfID.Text);
                        rpt.Run(false);
                        this.viewer1.Document = rpt.Document;

in the reporting class of AR

public NewActiveReport2(string sicilno)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            string strWhere = sicilno;
            strKomut = "select id,period,name,lastname from per015_ssk where id='" + strWhere + "' ";

 private void NewActiveReport2_ReportStart(object sender, EventArgs e)
        {
            DataAccess print_reader = new DataAccess();//create object of the class to handle datareader operations
            ok = print_reader.executar_re(strKomut);
            this.DataSource = print_reader;// bind datareader resultset

 private void NewActiveReport2_DataInitialize(object sender, EventArgs e)
        {
            Fields.Add("PERIOD");
            Fields.Add("ID");
            Fields.Add("NAME");
            Fields.Add("LASTNAME");
        }

private void NewActiveReport2_ReportEnd(object sender, EventArgs e)
        {
            ok.Close();
        }


private void NewActiveReport2_FetchData(object sender, FetchEventArgs eArgs)
        {
            try
            {
                ok.Read();
                // List them in order with datasource ordering not to get exception
                
                Fields["PERIOD"].Value = ok[0].ToString();
                Fields["ID"].Value = ok[1].ToString();
                Fields["NAME"].Value = ok[2].ToString();
                Fields["LASTNAME"].Value = ok[3].ToString();
                eArgs.EOF = false;
            }
            catch
            {
                eArgs.EOF = true;
            }
        }

And it does it.

Thanks Scott Willeke
snky

I am interested, so I'm glad you posted it. Use whatever, works out well for you, there is no "right" answer. However, here are some things for you to consider...

If you set an IDataReader instance to the DataSource property of the report you don't need to use FetchData. AR will automatically get the fields from the IDataReader instance and allow you to use them in the report. Just set the DataField property of a textbox to the name of the field (exactly as it is returned from the database).


It seems you're using your own data layer to actually execute the query. However, if you did let AR query the database directly you can use a sql statement with AR like the following:
this.DataSource.ConnectionString = "select id, period, name, lastname from per015_ssk where id='<%PerID|Enter PER ID|100>' ";

Then, outside of the report you can specify the value for it as follows:
myReportObject.Parameters["PerID"].Value = "some value";

ActiveReports will automatically update the query before it is executed. If you do not provide a value AR will prompt the end user for a value with "Enter PER ID" as the prompt (you can change that above).

Of course, if you must use an existing data layer then that is fine too!

Scott Willeke
GrapeCity Inc.

Thank you for your reply,

For the first part of your advise that is not to use FetchData event, what I did was I replaced datareader instance within ReportStart as you said.

private void NewActiveReport2_ReportStart(object sender, EventArgs e)
        {

DataAccess print_reader = new DataAccess
 ok = print_reader.executar_re(strKomut);    
this.DataSource = print_reader;

Fields["PERIOD"].Value = ok[0].ToString();  
Fields["ID"].Value = ok[1].ToString();                
Fields["NAME"].Value = ok[2].ToString();                
Fields["LASTNAME"].Value = ok[3].ToString();

        }

and it worked. But the rest of the advise can you elaborate further. Suppose I don't use the datalayerclass and use AR for sql query, 1-where do I put "this.DataSource.ConnectionString = "select id, period, name, lastname from per015_ssk where id='<%PerID|Enter PER ID|100>' "; "
2-where do I put "myReportObject.Parameters["PerID"].Value = "some value"; ". Is it the mainform ? Can I have a small sample of what you are advising. I like to find most appropriate and professional way of using AR, so open to any idea that helps.

Thanks
snky

This question has already been answered. Start a new discussion instead.