SQLCeResultSet does not update first row

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();
}
 
W

wavemill

Hello!

I think the problem id int i=1;
You start to the line 1 not to the line 0.
Hope you help,

Thanks,

Wavemill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top