本文介绍了使用 Visual Studio 2013 中的 SqlCeResultSet 访问 SQL Server Compact Edition 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Visual Studio 2013 中像这样使用 SqlCeResultSet

我已经安装了:

任何想法或建议将不胜感激.

提前致谢.

更新

也许问题是 SQL Server Compact 已从 Visual Studio 2013 中止,请参阅此 问题.在这种情况下,我的代码是否有任何替代方案?

解决方案

您错过了教程中的第 24 步 - 您需要打开连接:

 SqlCeCommand cmd = new SqlCeCommand("SELECT [Employee ID], [Last Name], [First Name], Photo FROM Employees",_conn);_conn.Open();SqlCeResultSet resultSet = cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);this.bindingSource1.DataSource = resultSet;

I would like use the SqlCeResultSet like this tutorial in Visual Studio 2013.

This is the code of my class Form1:

private SqlCeConnection _conn;
        public Form1()
        {
            InitializeComponent();
            _conn = new SqlCeConnection(@"Data Source = |DataDirectory|\Northwind.sdf");
            this.dataGridView1.AutoGenerateColumns = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SqlCeCommand cmd = new SqlCeCommand("SELECT [Employee ID], [Last Name], [First Name], Photo FROM Employees",_conn);
            SqlCeResultSet resultSet = cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);
            this.bindingSource1.DataSource = resultSet;
        }

Now I try to follow exactly the tutorial with my Database and when execute the line:

 SqlCeResultSet resultSet = cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable) 

throw this exception:

For more details this is my Solution Explorer:

And I have installed:

Any idea or suggestion would be appreciated.

Thanks in advance.

Updating

Maybe the problem is that SQL Server Compact is discontinued from Visual Studio 2013 see this question. In this case exist any alternative for my code?

解决方案

You missed step 24 in the tutorial - you need to open the connection:

 SqlCeCommand cmd = new SqlCeCommand("SELECT [Employee ID], [Last Name], [First Name], Photo FROM Employees",_conn);
 _conn.Open();
 SqlCeResultSet resultSet = cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);
 this.bindingSource1.DataSource = resultSet;

这篇关于使用 Visual Studio 2013 中的 SqlCeResultSet 访问 SQL Server Compact Edition 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 16:38