Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在VS 2012 express C中将SQL Server CE数据集添加到reportviewer#_C#_Visual Studio 2012_Dataset_Sql Server Ce - Fatal编程技术网

C# 在VS 2012 express C中将SQL Server CE数据集添加到reportviewer#

C# 在VS 2012 express C中将SQL Server CE数据集添加到reportviewer#,c#,visual-studio-2012,dataset,sql-server-ce,C#,Visual Studio 2012,Dataset,Sql Server Ce,我在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; c

我在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);
    }        
}

我可以看到datasource有数据,但按下按钮时报告仍然为空(没有错误,只是为空)。

尝试添加以下代码行:

 reportViewer1.LocalReport.ReportEmbeddedResource = 
   "Your_Name_Of_Project.Name_Of_Your_Report.rdlc";
 ds1 = new DataSet();
  datasource = new ReportDataSource("DayRep", ds1.Tables[0]);
如果您创建了自己的.rdlc报告文件,以便向reportViewer指示从何处获取数据,则应该这样做

还有,这行代码在哪里

this.reportViewer1.RefreshReport();
通常,它是由studio添加的(如果您使用它编写代码)。它应该在代码的末尾,就在
try
块的末尾。无论如何,它是“必须的”,没有它,你的报告真的会保持空白

此外,在我看来,您应该替换这一行代码:

 reportViewer1.LocalReport.ReportEmbeddedResource = 
   "Your_Name_Of_Project.Name_Of_Your_Report.rdlc";
 ds1 = new DataSet();
  datasource = new ReportDataSource("DayRep", ds1.Tables[0]);
关于这一点:

 ds1 = new DataSet("myDataSet"); //for exmaple, so to make dataSet have some name
然后重写这行代码:

 reportViewer1.LocalReport.ReportEmbeddedResource = 
   "Your_Name_Of_Project.Name_Of_Your_Report.rdlc";
 ds1 = new DataSet();
  datasource = new ReportDataSource("DayRep", ds1.Tables[0]);
下一步:

  dataSource = new ReportDataSource("myDataSet", ds1.Tables[0] as DataTable);
更新

好的,您不需要安装rdlc teamplate来通过ReportViewer运行和显示报告

如前所述,(在示例中),您可以这样写

// Set Processing Mode

    reportViewer.ProcessingMode = ProcessingMode.Local;

    // Set RDL file

    using (FileStream stream = new FileStream("report1.rdlc", FileMode.Open))
    {
        reportViewer.LocalReport.LoadReportDefinition(stream);
    }
因此,报告将加载到reperviewer中。这里的主要问题是我有一些.rdlc报告,所以我现在可以加载它们。若要在不使用模板的情况下创建它们,您可以使用另一种方法,以便以编程方式创建它们—也许这会对您有所帮助。另外,看看MSDN

UPD2
您可以使用以下命令查看
rdlc
报告的文本版本。但请记住,您无法将此
rdlc
准确加载到reportViewer中,并查看您希望它显示的数据。
.rdlc
只是一个例子,每个报告都应该由项目开发人员创建。主要原因是
.rdlc
我使用了您没有的数据集,因为它从您没有的数据库中获取数据。因此,我认为您查看此
rdlc
的唯一原因是了解。要成功创建
.rdlc
报告,您应该使用我之前提到的方法。要获得更多信息,您可以尝试在google中搜索“以编程方式生成报告定义”,或者像Visual Studio一样在IDE中找到创建报告的机会。

hm-m是的,尽管我没有创建任何rdlc文件,但在尝试结束时,刷新报告行在我的代码中。我刚刚将reportviewer添加到win表单中。我需要做些什么来创建rdlc文件吗。我想我是gona需要报告模板来创建它们,但如何将其添加到快速版?非常感谢您的回复!!!我将代码更改添加到我的项目中。如果我理解正确,我需要一个有效的rdlc文件,以便创建一个空文件。rdlc不会返回任何信息。谢谢你的链接,他们也很有帮助。如果您有时间,请给我发一封带有rdlc文件的电子邮件。再次感谢!我没有你的电子邮件,因为它是机密信息。你可以看看我答案的UPD2部分。