A
aknittel
Can someone explain to me why the first row in the result set is not
updated in the bound datagrid? When I inspect the database, ALL rows
(ProductID 1 to 20) have been updated as expected. If I take the loop
out and just updated row 1, it will not be reflected in the grid. This
ONLY happens with the first row.
It is not an option to use the SQLCeResultSet.SetValue, as the updates
to SQLCE will occur asychronously in another class. The whole point in
binding and using ResultSetOptions.Sensitive was that any changes in
the data source would be reflected.
===============================================
Assembly myAssembly = Assembly.GetExecutingAssembly();
string DBFolder = Path.GetDirectoryName(myAssembly.GetName().CodeBase);
sqlCEConnection = new SqlCeConnection("data source='" + DBFolder + "\\"
+ "Northwind.sdf" + "'; mode=Exclusive;");
sqlCEConnection.Open();
sqlCeCommand = sqlCEConnection.CreateCommand();
sqlCeCommand.CommandType = System.Data.CommandType.Text;
sqlCeCommand.CommandText = "SELECT * FROM Products ORDER BY [Product
ID]";
sqlCeResultSet =
sqlCeCommand.ExecuteResultSet(ResultSetOptions.Scrollable |
ResultSetOptions.Sensitive | ResultSetOptions.Updatable);
dgProducts.DataSource = sqlCeResultSet.ResultSetView;
for (int i = 1; i <= 20; i++)
{
sqlCeCommand = sqlCEConnection.CreateCommand();
sqlCeCommand.CommandText = "UPDATE Products SET [Product Name]
= 'XXX'
WHERE [Product ID] = " + i.ToString();
int recs = sqlCeCommand.ExecuteNonQuery();
sqlCeCommand.Dispose();
}
updated in the bound datagrid? When I inspect the database, ALL rows
(ProductID 1 to 20) have been updated as expected. If I take the loop
out and just updated row 1, it will not be reflected in the grid. This
ONLY happens with the first row.
It is not an option to use the SQLCeResultSet.SetValue, as the updates
to SQLCE will occur asychronously in another class. The whole point in
binding and using ResultSetOptions.Sensitive was that any changes in
the data source would be reflected.
===============================================
Assembly myAssembly = Assembly.GetExecutingAssembly();
string DBFolder = Path.GetDirectoryName(myAssembly.GetName().CodeBase);
sqlCEConnection = new SqlCeConnection("data source='" + DBFolder + "\\"
+ "Northwind.sdf" + "'; mode=Exclusive;");
sqlCEConnection.Open();
sqlCeCommand = sqlCEConnection.CreateCommand();
sqlCeCommand.CommandType = System.Data.CommandType.Text;
sqlCeCommand.CommandText = "SELECT * FROM Products ORDER BY [Product
ID]";
sqlCeResultSet =
sqlCeCommand.ExecuteResultSet(ResultSetOptions.Scrollable |
ResultSetOptions.Sensitive | ResultSetOptions.Updatable);
dgProducts.DataSource = sqlCeResultSet.ResultSetView;
for (int i = 1; i <= 20; i++)
{
sqlCeCommand = sqlCEConnection.CreateCommand();
sqlCeCommand.CommandText = "UPDATE Products SET [Product Name]
= 'XXX'
WHERE [Product ID] = " + i.ToString();
int recs = sqlCeCommand.ExecuteNonQuery();
sqlCeCommand.Dispose();
}