| | |
Active Reports passing variable to AR class
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 1
0
#2 Oct 14th, 2009
http://www.datadynamics.com/forums/82/ShowForum.aspx
Visit http://www.datadynamics.com/Help/Act...arameters.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
Visit http://www.datadynamics.com/Help/Act...arameters.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
•
•
Join Date: May 2009
Posts: 64
Reputation:
Solved Threads: 0
0
#3 Oct 18th, 2009
Just in case people are interestedi this is how I solved it.
in the reporting class of AR
And it does it.
Thanks Scott Willeke
snky
C# Syntax (Toggle Plain Text)
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
C# Syntax (Toggle Plain Text)
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
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 1
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.
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.
•
•
Join Date: May 2009
Posts: 64
Reputation:
Solved Threads: 0
0
#5 Oct 19th, 2009
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.
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
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.
C# Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- Passing Variable to another Class (Java)
- How to call a variable from other class (Java)
- Passing variable sql php (PHP)
- how to pass class variable to another class (Java)
Other Threads in the C# Forum
- Previous Thread: C# Meemory Acess Violation - Marshall.Copy
- Next Thread: Desinging in C# window application.
| Thread Tools | Search this Thread |
.net 2008 access actuate ajaxexample algorithm api apple applicationreengineering array asp.net basic blogger blogging c# c++ cio code coderisland coding combobox competition compiler computers database datagridview datetime desktop developer developers development e-commerce enum error eventhandlers file foreach form gdata google high-performance httpwebrequest index itconsulting java javascript linux list mailmerge microsystems mono mysql news os outsourcing panel password photoshop php platform pong post print programmers programming python remote remoting reporting richtextbox robot rss rumors security software softwaredevelopment sql sql-server statistics study supercomputing systemintegration table textbox tools ubuntu validation vb vb.net vb6 visual visualbasic visualbasic6 visualstudio webdevelopment windows winforms wordautomation wpf xml






