本文介绍了如何将SQL Server Compact Edition数据库连接到C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我尝试将我的SQL Server Compact Edition数据库连接到Crystal Report。我一直在寻找一整天,我已经发现很多问题相关到目前为止,在其他网站,但没有一个有效的答案。 我还发现这个问题在这个网站已要求VB.Net解决方案。和此链接,这是所有的 在SQL Server和Access中有其他解决方案的链接,这些链接都是通过XML来实现的, SQL Server解决方案 访问解决方案 一个简单的方法来连接一个SQL Server CE数据库到Crystal Report实际工作?解决方案有用 CodeProject示例 我将演示一个更简单的示例,以便更容易找出。 Winform并添加一个按钮和 CrystalReportViewer 控件。 添加一个DataSet文件)到您的项目中使用解决方案资源管理器中的添加 - >新建项目。之后,向DataSet添加一个DataTable。 DataTable 。最好将它们命名为与您要在报告中显示的列相同。列数取决于在Crystal报表中应显示的列数。 使用add - > New Items报表向导,选择项目数据源的ADO.NET数据集作为Crystal报表的数据源,并选择刚刚在DataSet中创建的数据表作为Crystal报表的选定表。 单击完成,您的列将自动添加到 CrystalReport 。 转到按钮点击事件,并在其中写入这些代码。 code> private void btnGo_Click(object sender,EventArgs e) { CrReport2 objRpt = new CrReport2(); string query =Select Name,Number from tblInfo; //你的sql查询 SqlCeConnection conn = new SqlCeConnection( @Data Source = | DataDirectory | \myDB.sdf; Persist Security Info = False); //您的连接 SqlCeDataAdapter adepter = new SqlCeDataAdapter(query,conn); DsReport Ds = new DsReport(); // DsReport是我的数据集 adepter.Fill(Ds,customer); // customer是我的数据集中的数据集 objRpt.SetDataSource(Ds); crystalReportViewer1.ReportSource = objRpt; 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.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.There are other links with solutions in SQL Server and Access which don't help.SQL Server solutionAccess SolutionI'm wondering is there a simple way to connect a SQL Server CE database to Crystal Report which actually works? 解决方案 So I found my solution thanks to this helpful CodeProject sampleI will demonstrate an easier sample to make it easier to figure it out.Create a Winform and add a button and a CrystalReportViewer control to it.Add a DataSet (*.xsd file) to your project using add -> New Items in solution explorer. After that, add a DataTable to the DataSet.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.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.Click finish and your columns will automatically be added in 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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 15:52