I am developing a WinFrom application. I am using SDF database to store data.
The below code snippet to load the data to datagrid from DataBase is hanging the application. When I am clicking on the datagrid,
“Invalid attempt to call method Updatable when SqlResultSet is closed” exception is being thrown.
public partial class Form1 : Form
{
private SqlCeConnection _conn;
public Form1()
{
InitializeComponent();
_conn = new SqlCeConnection(@"Data Source = |DataDirectory|\Database1.sdf");
this.dataGridView1.AutoGenerateColumns = true;
}
private void Form1_Load(object sender, EventArgs e)
{
SqlCeCommand sqlcmd = new SqlCeCommand();
sqlcmd.Connection = _conn;
sqlcmd.CommandText = "SELECT ID, UserName FROM Table1";
_conn.Open();
SqlCeResultSet rs = sqlcmd.ExecuteResultSet(ResultSetOptions.Scrollable);
this.bindingSource1.DataSource = rs;
_conn.Close();
}
}
Can anybody please look into it?
Try this
You can check this post too. You will need to keep connection open for binding dataset directly. Instead of doing that map it to some local object and bind that.
Hope this works for you.