0
我想在Windows窗體應用程序中的報表窗體中顯示一些數據。爲此,我在本地模式下使用ReportViewer。當我運行報告時,它顯示空的報告,根本沒有錯誤!這裏是我的代碼:在VS2010中的本地模式ReportViewer中的空數據
public partial class Form1 : Form
{
String thisConnectionString = "Data Source=AZEEM-NAWAZ;Initial Catalog=IEPL_Attendance_DB;Trusted_Connection = true;";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'DataSetProducts.ShowProductByCategory' table. You can move, or remove it, as needed.
//this.ShowProductByCategoryTableAdapter.Fill(this.DataSetProducts.ShowProductByCategory);
//this.reportViewer1.RefreshReport();
//reportViewer1.Visible = false;
SqlConnection thisConnection = new SqlConnection(thisConnectionString);
System.Data.DataSet thisDataSet = new System.Data.DataSet();
string cmdText = "USE [IEPL_Attendance_DB] EXEC [ShowProductByCategory]";
SqlCommand cmd = new SqlCommand(cmdText, thisConnection);
SqlDataAdapter data_ad = new SqlDataAdapter(cmd);
data_ad.Fill(thisDataSet);
/* Associate thisDataSet (now loaded with the stored
procedure result) with the ReportViewer datasource */
ReportDataSource datasource = new ReportDataSource("DataSetProducts_DataSet1", thisDataSet.Tables[0]);
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(datasource);
if (thisDataSet.Tables[0].Rows.Count == 0)
{
MessageBox.Show("Sorry, no products under this category!");
}
reportViewer1.LocalReport.Refresh();
//MessageBox.Show("Total Rows are: " + thisDataSet.Tables[0].Rows[0]["EmployeeName"].ToString());
}
private void reportViewer1_Load(object sender, EventArgs e)
{
}
}
這裏有report.rdlc屬性:
StoredProcedure的「ShowProductByCategory」的返回數據,我已經通過顯示行通過的MessageBox算驗證!
沒有人有什麼想法? – Azeem 2012-02-18 08:30:47