I am programming in C# for the .net compact framework 2.0.
I am binding controls on the screen to my SqlCe database using
ResultSetViews. Everything works fine, as long as there are rows
in the table when I create a ResultSet. If I create a ResultSet
when there are no rows in the table, and then later add rows to the
table, and after that set up the databindings, the bindings won't work
(Controls who's Text property is bound display no text at all).
Do I need to do something to update the resultSetViews This is
(sort of) how I am doing it:
cmndDB = new SqlCeCommand("SELECT * FROM MyTable", dbConn);
SqlCeResultSet rs = cmndDB.ExecuteResultSet();
ResultSetView rv = rs.ResultSetView;
...
cmndDB.CommandText = "INSERT INTO MyTable VALUES (...)";
...
Label l = new Label();
...
l.DataBindings.Add("Text", rv, "someColumnName");

Losing Databinding with ResultSetViews
Poma
jakeb16
Rups11
Sam_res03
ron nash
If you’d like RS to be aware of changes in the database, you need to specify sensitivity on RS:
SqlCeResultSet rs = cmndDB.ExecuteResultSet(ResultSetOptions.Sensitive);
Sensetive RS is the slowest and I don’t think it would fire an event to notify bound controls of data changes even though you would get updated data if you rebind ot read it from RS.
So, better way to go would be to make it updatable and add records to RS itself instead of executing separate queries:
SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable | ResultSetOptions.Scrollable);
SqlCeUpdatableRecord rec = rs.CreateRecord();
rec.SetInt32(0, 34);
rec.SetDecimal(1, (decimal)44.66);
rec.SetString(2, "Sample text");
rs.Insert(rec);
hazz
You are binding to RSV in any case. RS implements IListSource interface which actually creates and returns ResultSetView class.
Binding context is set up a bit differently though which is probably why it works the way you want. So, yes, it's fine and RS supports it.