在 Report Viewer 中设置参数
Set parameters in Report Viewer
我希望我的报告显示所有库存低于 搜索 文本框中插入的值的产品。有错误。
这是存储过程:
CREATE PROCEDURE [dbo].[GetInventoryReport]
@Stock int
AS
SELECT *
FROM Product
WHERE Stock < @Stock
ORDER BY Stock ASC
这是用户在搜索文本框中输入值时的代码。
private void txtSearch_TextChanged(object sender, EventArgs e)
{
DataTable dtbl = GetInventoryReport_Result();
rptInventoryStock.Visible = true;
rptInventoryStock.LocalReport.ReportPath = "InventoryReport.rdlc";
rptInventoryStock.LocalReport.DataSources.Clear();
rptInventoryStock.LocalReport.Add(new ReportDataSource("IOOP_DatabaseDataSet", dtbl));
this.rptInventoryStock.RefreshReport();
}
这是GetInventoryReport_Result()
的函数:
private DataTable GetInventoryReport_Result()
{
DataTable dtbl = new DataTable();
try
{
SqlCommand sqlCmd = new SqlCommand("GetInventoryReport", sqlCon);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@Stock", txtSearch.Text.Trim());
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dtbl);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Message");
}
finally
{
if (sqlCon != null)
sqlCon.Close();
}
return dtbl;
}
错误:
'Microsoft.Reporting.WinForms.LocalReport' does not contain a
definition for 'Add' and no extension method 'Add' accepting a first
argument of type 'Microsoft.Reporting.WinForms.LocalReport' could be
found (are you missing a using directive or an assembly reference?)
你错过了.DataSources
替换:
rptInventoryStock.LocalReport.Add(new ReportDataSource("IOOP_DatabaseDataSet", dtbl));
与
rptInventoryStock.LocalReport.DataSources.Add(new ReportDataSource("IOOP_DatabaseDataSet", dtbl));
我希望我的报告显示所有库存低于 搜索 文本框中插入的值的产品。有错误。
这是存储过程:
CREATE PROCEDURE [dbo].[GetInventoryReport]
@Stock int
AS
SELECT *
FROM Product
WHERE Stock < @Stock
ORDER BY Stock ASC
这是用户在搜索文本框中输入值时的代码。
private void txtSearch_TextChanged(object sender, EventArgs e)
{
DataTable dtbl = GetInventoryReport_Result();
rptInventoryStock.Visible = true;
rptInventoryStock.LocalReport.ReportPath = "InventoryReport.rdlc";
rptInventoryStock.LocalReport.DataSources.Clear();
rptInventoryStock.LocalReport.Add(new ReportDataSource("IOOP_DatabaseDataSet", dtbl));
this.rptInventoryStock.RefreshReport();
}
这是GetInventoryReport_Result()
的函数:
private DataTable GetInventoryReport_Result()
{
DataTable dtbl = new DataTable();
try
{
SqlCommand sqlCmd = new SqlCommand("GetInventoryReport", sqlCon);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@Stock", txtSearch.Text.Trim());
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dtbl);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Message");
}
finally
{
if (sqlCon != null)
sqlCon.Close();
}
return dtbl;
}
错误:
'Microsoft.Reporting.WinForms.LocalReport' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'Microsoft.Reporting.WinForms.LocalReport' could be found (are you missing a using directive or an assembly reference?)
你错过了.DataSources
替换:
rptInventoryStock.LocalReport.Add(new ReportDataSource("IOOP_DatabaseDataSet", dtbl));
与
rptInventoryStock.LocalReport.DataSources.Add(new ReportDataSource("IOOP_DatabaseDataSet", dtbl));