Losing Databinding with ResultSetViews

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");


Answer this question

Losing Databinding with ResultSetViews

  • Poma

    This forum doesn't cover the compact frameworks. I'll move the question over to a more appropriate one.

  • jakeb16

    Thanks for the response. Unfortunately, the bindings are still not updated. It seems that if I create the views when there are no rows in the table, the bindings will never function properly. I checked via a SELECT statement, and the rows are definitely being added properly using the 'CreateRecord / Insert' methods, making sure to use updatable and scrollable. But when I show my screens that are bound, all of the bound fields are blank. If I calculate the views after inserting the rows, the binding works properly, but if i were to recalculate the views every time I added a new row, I would have to redo all of my bindings, right
  • Rups11

    Thank you very much!
  • Sam_res03

    Okay, I may have come up with a solution. Previously, I was binding all of my controls to the ResultSetViews of the SqlCeResultSets that I was using, as per instructions on the MSDN tutorial. I found that when I bind directly to the SqlCeResultSet, the problem goes away, regardless of whether there are rows in the database. This seems to be an OK solution, but I am hesitant to use it just because it was specifically mentioned on the MSDN site that you should bind to the ResultSetViews. Is it a bad idea to just bind directly to the ResultSet
  • 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.



  • Losing Databinding with ResultSetViews