问题描述
亲爱的所有人,
请给我解决方案我的代码如下通过两个参数:
一个参数用于选择日期形式DropDownList
第二个使用下拉列表选择状态名称
SQl中的表格str
州名,地区名称,疫苗数量,日期
我可以看到这两个参数在浏览器中测试报告但在选择状态名称时没有报告显示:
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Data;
使用System.Data.SqlClient;
使用Microsoft.Reporting.WebForms ;
使用System.Configuration;
公共部分类报告:System.Web.UI.Page
{
protected void btnShowReport_Click(object sender,EventArgs e)
{
//重置
ReportViewer1.Reset();
//数据源
DataTable dt = GetData();
ReportDataSource rds = new ReportDataSource(DataSet1, dt);
ReportViewer1.LocalReport.DataSources.Add(rds);
//路径
ReportViewer1.LocalReport.ReportPath =报告。 rdlc;
//参数
ReportParameter [] rptParams = new ReportParameter [] {
new ReportParameter(StateName,DropDownList1.SelectedValue )};
// referesh
ReportViewer1.LocalReport.Refresh();
}
私有DataTable GetData()
{
//连接数据库
DataTable dt = new DataTable();
String connStr = @数据源= GIS-SERVER;初始目录= MIDB;集成安全性=真;
使用(SqlConnection cn = new SqlConnection(connStr))
{
SqlCommand cmd = new SqlCommand(DailyMIReportFinal1,cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter( cmd);
adp.Fill(dt);
}
返回dt;
}
}
-------------------- ------------------------
商店程序如下:
创建程序DailyMIReport
As
选择StateName,Date
,SUM(转换(int,[NoOfChildrenVaccinated]))AS [Total_No_of_Children_Vaccinated],SUM(转换(int,[NoOfSessionsHeld]))[Total_No_of_Session_Held]
来自MIREPORTFINAL
GROUP BY州名,日期
--------------------- -----------------------
Dear All,
please give me the solution My code is as under for the passing two parameters:
One parameter is for selecting the Date form the DropDownList
Second selecting the Name of State using Dropdownlist
table str in SQl
State Name ,District Name,No of vaccine, Date
I can see both of the parameter while testing the report in browser but when selecting the state Name no report showing :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
using System.Configuration;
public partial class Report : System.Web.UI.Page
{
protected void btnShowReport_Click(object sender, EventArgs e)
{
//Reset
ReportViewer1.Reset();
//Datasource
DataTable dt = GetData();
ReportDataSource rds = new ReportDataSource("DataSet1",dt);
ReportViewer1.LocalReport.DataSources.Add(rds);
//Path
ReportViewer1.LocalReport.ReportPath = "Report.rdlc";
//Parameter
ReportParameter[] rptParams = new ReportParameter[] {
new ReportParameter("StateName",DropDownList1.SelectedValue)};
//referesh
ReportViewer1.LocalReport.Refresh();
}
private DataTable GetData()
{
//Connection to database
DataTable dt=new DataTable();
String connStr =@"Data Source=GIS-SERVER;Initial Catalog=MIDB;Integrated Security=True";
using (SqlConnection cn = new SqlConnection(connStr))
{
SqlCommand cmd = new SqlCommand("DailyMIReportFinal1", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
}
return dt;
}
}
--------------------------------------------
Store procedure is as under :
Create Procedure DailyMIReport
As
Select StateName,Date
,SUM(Convert(int,[NoOfChildrenVaccinated])) AS [Total_No_of_Children_Vaccinated],SUM(Convert(int,[NoOfSessionsHeld])) As [Total_No_of_Session_Held]
FROM MIREPORTFINAL
GROUP BY StateName,Date
--------------------------------------------
这篇关于使用C#asp.net SQL Server在RDLC中传递DropdownList参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!