更新在带有数据集和表适配器的 SQLCe 3.5 上未生效
我们使用 VS2010 数据连接设计向导来定义与 SQLCe 数据库的连接,其中仅包含一张表 (database="UserMetrics" table="User")。尽我们所能,更新似乎不起作用,我已经浏览过 SO 和 MSDN 上的帖子,但看不到明显的错误...
//initialize
UserMetricsDataSet umDataSet = new UserMetricsDataSet( );
UserMetricsDataSetTableAdapters.UserTableAdapter umTableAdapter = new UserMetricsDataSetTableAdapters.UserTableAdapter( );
// check that test data is there and count is correct
umTableAdapter.Fill( umDataSet.User );
UserMetricsDataSet.UserRow umRow = (UserMetricsDataSet.UserRow)umds.User.Rows[0];
int count = umDataSet.User.Rows.Count; //yep its there
//lets add some rows
for (int i = 0; i < 100; i++)
umDataSet.User.AddUserRow( "smith", (float)54, (float)3, 1);
umds.User.AcceptChanges( );
//umTableAdapter.Update(umDataSet.User); //tried this also ... no change...
// there are now 101 rows !!
int count = umDataSet.User.Rows.Count; //yep its there
umRow = (UserMetricsDataSet.UserRow)umds.User.Rows[101];
//lets double check
umTableAdapter.Fill( umDataSet.User );
int count = umds.UserMetris.Rows.Count; //huh!!! count==1 ???
We used the VS2010 data connection design wizard to define a connection to a SQLCe database with just one table (database="UserMetrics" table="User"). Try as we might the update doesn't seem to hold, I've been through posts on SO and MSDN but can't see the glaring error...
//initialize
UserMetricsDataSet umDataSet = new UserMetricsDataSet( );
UserMetricsDataSetTableAdapters.UserTableAdapter umTableAdapter = new UserMetricsDataSetTableAdapters.UserTableAdapter( );
// check that test data is there and count is correct
umTableAdapter.Fill( umDataSet.User );
UserMetricsDataSet.UserRow umRow = (UserMetricsDataSet.UserRow)umds.User.Rows[0];
int count = umDataSet.User.Rows.Count; //yep its there
//lets add some rows
for (int i = 0; i < 100; i++)
umDataSet.User.AddUserRow( "smith", (float)54, (float)3, 1);
umds.User.AcceptChanges( );
//umTableAdapter.Update(umDataSet.User); //tried this also ... no change...
// there are now 101 rows !!
int count = umDataSet.User.Rows.Count; //yep its there
umRow = (UserMetricsDataSet.UserRow)umds.User.Rows[101];
//lets double check
umTableAdapter.Fill( umDataSet.User );
int count = umds.UserMetris.Rows.Count; //huh!!! count==1 ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设 umDataSet 与 umds 相同。
又怎样呢?
或者颠倒顺序怎么办?
TableAdapter.Update()
方法根据 DataTable 中的更改将更新发送回数据库。如果您首先接受更改,则每个 DataTable 行上的RowState
都会重置,因此不会发现任何更新可发送回数据库。来自 MSDN:
I'm assuming
umDataSet
is the same thing asumds
.What about?
Or what about reversing the order? The
TableAdapter.Update()
method sends updates back to the database based on the changes in the DataTable. If you accept the changes first, then theRowState
is reset on each DataTable row, so there are no updates found to send back to the database.From MSDN: