【发布时间】:2011-01-24 05:04:36
【问题描述】:
我很想在 VS2010 中使用 ReportViewer 控件在本地报告中传递参数。用户点击一个商家,然后按下一个按钮(未显示),然后呈现报告。
我试过使用这个视频:How-to Pass Parameter to Report Viewer - YouTube
问题:代码不起作用 - 在底部的 xxxx 附近我不知道里面应该有什么
问题:我很想摆脱这段代码并使用 linqtosql 或更简单的东西。
protected void Page_Load(object sender, EventArgs e)
{
DataSet1TableAdapters.MerchantNamesTableAdapter merchantNamesTableAdapter = new DataSet1TableAdapters.MerchantNamesTableAdapter();
ddlMerchants.DataSource = merchantNamesTableAdapter.GetDataAllMerchants();
ddlMerchants.DataTextField = "Name";
ddlMerchants.DataValueField = "MerchantUID";
ddlMerchants.DataBind();
ReportViewer1.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
ReportViewer1.Visible = true;
var newDataSet = new DataSet();
SqlConnection sqlConnection = new SqlConnection("Data Source=.;Initial Catalog=myDataBase;Integrated Security=True");
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = "select * from merchant where merchantUID = @MerchantUID";
sqlCommand.Parameters.AddWithValue("@MerchantUID", ddlMerchants.SelectedValue);
sqlDataAdapter.SelectCommand = sqlCommand;
sqlDataAdapter.Fill(newDataSet);
ReportDataSource datasource = new ReportDataSource(xxxx, newDataSet.Tables(0));
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
ReportViewer1.LocalReport.Refresh();
}
【问题讨论】:
标签: c# sql reporting-services reportviewer