944,184 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2873
  • C# RSS
Oct 14th, 2009
0

Active Reports passing variable to AR class

Expand Post »
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
Similar Threads
Reputation Points: 4
Solved Threads: 0
Junior Poster in Training
snakay is offline Offline
78 posts
since May 2009
Oct 14th, 2009
0
Re: Active Reports passing variable to AR class
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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
scottwilleke is offline Offline
3 posts
since Oct 2009
Oct 18th, 2009
0
Re: Active Reports passing variable to AR class
Just in case people are interestedi this is how I solved it.
C# Syntax (Toggle Plain Text)
  1. private void toolStripButton1_Click(object sender, EventArgs e)
  2. //Create the report and assign the data source
  3. NewActiveReport2 rpt = new NewActiveReport2(dfID.Text);
  4. rpt.Run(false);
  5. this.viewer1.Document = rpt.Document;

in the reporting class of AR
C# Syntax (Toggle Plain Text)
  1.  
  2. public NewActiveReport2(string sicilno)
  3. {
  4. //
  5. // Required for Windows Form Designer support
  6. //
  7. InitializeComponent();
  8. string strWhere = sicilno;
  9. strKomut = "select id,period,name,lastname from per015_ssk where id='" + strWhere + "' ";
  10.  
  11. private void NewActiveReport2_ReportStart(object sender, EventArgs e)
  12. {
  13. DataAccess print_reader = new DataAccess();//create object of the class to handle datareader operations
  14. ok = print_reader.executar_re(strKomut);
  15. this.DataSource = print_reader;// bind datareader resultset
  16.  
  17. private void NewActiveReport2_DataInitialize(object sender, EventArgs e)
  18. {
  19. Fields.Add("PERIOD");
  20. Fields.Add("ID");
  21. Fields.Add("NAME");
  22. Fields.Add("LASTNAME");
  23. }
  24.  
  25. private void NewActiveReport2_ReportEnd(object sender, EventArgs e)
  26. {
  27. ok.Close();
  28. }
  29.  
  30.  
  31. private void NewActiveReport2_FetchData(object sender, FetchEventArgs eArgs)
  32. {
  33. try
  34. {
  35. ok.Read();
  36. // List them in order with datasource ordering not to get exception
  37.  
  38. Fields["PERIOD"].Value = ok[0].ToString();
  39. Fields["ID"].Value = ok[1].ToString();
  40. Fields["NAME"].Value = ok[2].ToString();
  41. Fields["LASTNAME"].Value = ok[3].ToString();
  42. eArgs.EOF = false;
  43. }
  44. catch
  45. {
  46. eArgs.EOF = true;
  47. }
  48. }

And it does it.

Thanks Scott Willeke
snky
Reputation Points: 4
Solved Threads: 0
Junior Poster in Training
snakay is offline Offline
78 posts
since May 2009
Oct 18th, 2009
0

Great! Some things notes to consider

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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
scottwilleke is offline Offline
3 posts
since Oct 2009
Oct 19th, 2009
0
Re: Active Reports passing variable to AR class
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.
C# Syntax (Toggle Plain Text)
  1.  
  2. private void NewActiveReport2_ReportStart(object sender, EventArgs e)
  3. {
  4.  
  5. DataAccess print_reader = new DataAccess
  6. ok = print_reader.executar_re(strKomut);
  7. this.DataSource = print_reader;
  8.  
  9. Fields["PERIOD"].Value = ok[0].ToString();
  10. Fields["ID"].Value = ok[1].ToString();
  11. Fields["NAME"].Value = ok[2].ToString();
  12. Fields["LASTNAME"].Value = ok[3].ToString();
  13.  
  14. }

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
Reputation Points: 4
Solved Threads: 0
Junior Poster in Training
snakay is offline Offline
78 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: C# Meemory Acess Violation - Marshall.Copy
Next Thread in C# Forum Timeline: Desinging in C# window application.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC