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:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.SqlServerCe.dll Additional information: ExecuteResultSet: Connection property has not been initialized.
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;