我在 C# 中使用 VS 2012 express 编码,并且在将数据从数据集(我使用 SQL Server CE)添加到报表视图时遇到问题。我的代码是这样的:
private void button1_Click(object sender, EventArgs e)
{
System.Data.SqlServerCe.SqlCeConnection con;
System.Data.SqlServerCe.SqlCeDataAdapter da;
DataSet ds1;
con = new System.Data.SqlServerCe.SqlCeConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["MySalon.Properties.Settings.MySalonConnectionString"].ToString();
string sql = "SELECT * FROM CUSTOMER_PAYMENTS;";
try
{
con.Open();
da = new System.Data.SqlServerCe.SqlCeDataAdapter(sql, con)
ds1 = new DataSet();
da.Fill(ds1, "DayRep");
ReportDataSource datasource;
datasource = new ReportDataSource("DayRep", ds1.Tables[0]);
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(datasource);
con.Close();
reportViewer1.LocalReport.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我可以看到数据源有数据,但按下按钮时报告保持空白(没有错误只是空白)。