Active Reports passing variable to AR class

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 64
Reputation: snakay has a little shameless behaviour in the past 
Solved Threads: 0
snakay snakay is offline Offline
Junior Poster in Training

Active Reports passing variable to AR class

 
0
  #1
Oct 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: scottwilleke is an unknown quantity at this point 
Solved Threads: 1
scottwilleke scottwilleke is offline Offline
Newbie Poster
 
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
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 64
Reputation: snakay has a little shameless behaviour in the past 
Solved Threads: 0
snakay snakay is offline Offline
Junior Poster in Training
 
0
  #3
Oct 18th, 2009
Just in case people are interestedi this is how I solved it.
  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
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: scottwilleke is an unknown quantity at this point 
Solved Threads: 1
scottwilleke scottwilleke is offline Offline
Newbie Poster

Great! Some things notes to consider

 
0
  #4
Oct 18th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 64
Reputation: snakay has a little shameless behaviour in the past 
Solved Threads: 0
snakay snakay is offline Offline
Junior Poster in Training
 
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.
  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
Reply With Quote Quick reply to this message  
Reply

Tags
c#, programming, reporting, visualbasic

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC