本文介绍了如何SQL Server Compact Edition数据库连接到水晶报表在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想我的SQL Server Compact Edition数据库连接到Crystal报表。我一直在寻找一整天我发现在其他网站上至今与之相关的许多问题,但什么都没有工作的答​​案。I'm trying to connect my SQL Server Compact Edition database to Crystal Report. I've been searching all day long and I've found many question related to it so far on other websites, but none had a working answer.我也发现这个问题本网站已要求VB.Net的解决方案。和此链接这是所有在互联网和有一个令人困惑的方式通过XML,我无法弄清楚做到这一点。I also found this question in this site which has asked for VB.Net solution. And this link which is all over the internet and has a confusing way to do it by XML, which I couldn't figure it out.有与SQL Server的解决方案,因而可别等环节ŧ帮助。There are other links with solutions in SQL Server and Access which don't help. 的 SQL Server解决方案 的接入解决方案SQL Server solutionAccess Solution我想知道有没有一个简单的方法来连接SQL Server CE数据库,以水晶报表哪些实际工作?I'm wondering is there a simple way to connect a SQL Server CE database to Crystal Report which actually works?推荐答案所以,我发现我的解决方案感谢这个乐于助人 CodeProject上样品So I found my solution thanks to this helpful CodeProject sample我将演示一个更简单的样本,使其更容易弄明白。I will demonstrate an easier sample to make it easier to figure it out. 创建一个WinForm并添加一个按钮和一个的CrystalReportViewer 控制它。添加一个DataSet(* .xsd文件)使用您的项目添加 - >在Solution Explorer中的新项目。在此之后,一个DataTable添加到DataSetAdd a DataSet (*.xsd file) to your project using add -> New Items in solution explorer. After that, add a DataTable to the DataSet. 添加列数据表。这是更好地为它们命名一样的,你要显示在您的报告中的列。列数取决于多少列应在Crystal报表显示Add columns to DataTable. It's better to name them the same as the columns you are going to display on your report. The number of columns depends on how many columns should be displayed in the Crystal report.添加水晶报表到项目中使用添加 - >新项目并使用报表向导,选择项目数据源,水晶报表的数据源的ADO.NET数据集,并选择您只需在您的DataSet中创建的数据表,水晶报表的选择的表。Add a Crystal Report into the project using add -> New Items and using the Report Wizard, choose ADO.NET DataSets of the Project data source as the data source of the Crystal Report and select the data table you just created in your DataSet, as the selected table of the Crystal Report. 点击完成,你的列将自动 CrystalReport 添加。转到按钮单击事件,并在写这些代码。Go to the button click event and write these codes in it.private void btnGo_Click(object sender, EventArgs e){ CrReport2 objRpt = new CrReport2(); string query = "Select Name,Number from tblInfo"; //Your sql query SqlCeConnection conn = new SqlCeConnection( @"Data Source=|DataDirectory|\myDB.sdf;Persist Security Info=False"); //Your connection SqlCeDataAdapter adepter = new SqlCeDataAdapter(query, conn); DsReport Ds = new DsReport(); //DsReport is my dataset adepter.Fill(Ds, "customer"); //customer is my datatable in dataset objRpt.SetDataSource(Ds); crystalReportViewer1.ReportSource = objRpt;} 享受您的报告:)Enjoy your report :) 这篇关于如何SQL Server Compact Edition数据库连接到水晶报表在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-11 00:41