This is a migrated thread and some comments may be shown as answers.

handing in a SQL string to my reportviewer

2 Answers 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 12 Aug 2013, 09:12 PM
Hello All,

I have a report which works fine and it is set to my report viewer.  I have the SQL select statement hard coded.  I have a dropdown box on the same page and I want to append that user name to the select statement.  I am a bit confounded on how to change the select statement.  Here is the code and I want to dynamically hand in the user id (which is 4 in my hard coded case).  I know how to get the selected item out of the dropdown...it just isn't clear how I get the web page to hand it into the report.  Any thoughts? 
Thank you.
William

public ReportClass()

{

StringBuilder sb = new StringBuilder();

InitializeComponent();

 

sb.Append("select SY.name_system, SE.id_employee, SE.id_system, SE.id_user, SE.date_change").Append(" ");

sb.Append("from Secured SE").Append(" ");

sb.Append("inner join Systems SY on SY.id_system=SE.id_system").Append(" ");

sb.Append("where SE.is_active=1 and SE.id_employee=").Append("4").Append(" ");

sb.Append("Order by SE.date_change DESC");

sqlSource.SelectCommand = sb.ToString();

txtRunDate.Value = DateTime.Today.ToShortDateString();

}



2 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 15 Aug 2013, 06:44 PM
Hello William,

Try using parametrized SQL query, where the SQL parameter can be mapped to a report parameter. The report parameter can be passed through the report source object or displayed in the ReportViewer parameters area. For more details take a look at the following materials:

I hope this helps.


Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
William
Top achievements
Rank 1
answered on 17 Aug 2013, 08:02 PM
Thanks Stef.

I found this to be the best option for flexibility.   I don't like parameters on open ended reports.  I like to give the users the ability to pick stuff off of the page as parameters and send them along on a select string.

protected void btnReports_Click(object sender, EventArgs e)

{

StringBuilder sb = new StringBuilder();

Master.SetStatus("Reports");

sb.Append("select SY.name_system, SE.id_employee, SE.id_system, SE.id_user, SE.date_change").Append(" ");

sb.Append("from Secured SE").Append(" ");

sb.Append("inner join Systems SY on SY.id_system=SE.id_system").Append(" ");

sb.Append("where SE.is_active=1 and SE.id_employee=");

sb.Append(int.Parse(ddEmployeeList.SelectedItem.Value).ToString()).Append(" ");

sb.Append("Order by SE.date_change DESC");

ReportViewer1.Report = new ReportClass(sb.ToString(), ddEmployeeList.SelectedItem.ToString());

ReportViewer1.RefreshReport();

}


William
Tags
General Discussions
Asked by
William
Top achievements
Rank 1
Answers by
Stef
Telerik team
William
Top achievements
Rank 1
Share this question
or