TableAdapter.Update不提交

编程入门 行业动态 更新时间:2024-10-26 18:21:44
本文介绍了TableAdapter.Update不提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到了tableadapter.update无法写入本地访问db(即MS Access 2007 mdb)的问题.我正在使用C#在VS2010中工作.我正在使用强类型数据集(XSD). 我的应用程序将数据绘制到本地数据库中.当我说本地时,是指我将Access DB复制到项目中,并且app.config中的数据源反映了| Data Directory |.作为它的连接字符串的一部分. 我可以毫不费力地添加行,但是如果我尝试修改现有行中的值,则似乎无法在基础数据库中得到它.我有一个打印/不打印字段(在访问mdb中定义为是/否"字段),我希望我的用户能够切换该字段.但是,以下方法似乎并未更新基础表,也不会引发任何错误:

I have an issue with tableadapter.update not writing to a local access db, which is MS access 2007 mdb. I am working in VS2010 using c#. I am using a strongly typed dataset (XSD). My application draws data into a local db. When I say local, I mean in the sense that I copied the Access DB to the project and the datasource in app.config reflects |Data Directory| as part of it''s connection string. I can add rows with out any difficulty, but if I attempt to modify values in an existing row, I don''t seem to get that in the underlying database. I have a print/noprint field (defined in access mdb as a Yes/No field) which I want my user to be able to toggle. Yet, the following method doesn''t seem to update the underlying table, nor does it throw any errors:

private void togglePrintToolStripMenuItem_Click(object sender, EventArgs e) { dsH3TableAdapters.lblSourceTableAdapter taLblSource = new dsH3TableAdapters.lblSourceTableAdapter(); taLblSource.FillAll(this.dsH3.lblSource); dsH3.lblSourceDataTable dtLabels = taLblSource.GetDataAll(); foreach (dsH3.lblSourceRow rowLabels in dtLabels) { bool printingState = rowLabels.bPrintLabel; rowLabels.BeginEdit(); rowLabels.bPrintLabel = !printingState; rowLabels.EndEdit(); rowLabels.AcceptChanges(); taLblSource.Update(this.dsH3.lblSource); } taLblSource.FillAll(this.dsH3.lblSource); }

我可能不完全了解如何使用表适配器,数据表和数据行,但是最近几天我做了很多搜索,很多人似乎都遇到了这个问题,没有明确定义的解决方案. 我尝试了各种beginedit,endedit,acceptchanges,忽略了这些等等,但都无济于事.我可以通过使用rowLabels.Order_No和rowLabels.LineNo(它们是表的主键字段,并且在XSD中定义为此类)在xsd中调用更新查询来更新行,但这是一个比较耗时的操作,并且如果可以的话,我宁愿进行上述工作. 我认为使用本地数据库不是问题,我已阅读 MSDN 的问题,事实是我添加行的方法运行良好,并且所有在xsd中调用查询的方法都运行良好.只是该行的直接更新似乎不起作用. 我读了一篇文章说,如果数据库中的某些字段允许使用空值,那可能是个问题,但我确实允许某些字段使用空值. 感谢任何帮助.谢谢.

It is possible that I don''t fully understand how to use tableadapters and datatables and datarows, but I have done a lot of searching the last few days and a lot of people seem to have this problem with no clearly defined solution. I''ve tried a variety of beginedit, endedit, acceptchanges, omitting these, etc, to no avail. I can update the rows by calling an update query in the xsd using rowLabels.Order_No and rowLabels.LineNo (which are the primary key fields for the table and defined as such in the XSD), but that is a more time-consuming operation and I would rather make the above work, if I can. I don''t think this is an issue with using the local database, I have read the article at MSDN about that, and the fact is my methods to add rows works fine, and all methods that call a query in the xsd work fine. It is just this direct update of the row that doesn''t seem to work. I read a post saying this might be a problem if some fields in the db allow nulls, I do allow nulls in some fields. Appreciate any help. Thank you.

推荐答案

这只是一个猜测,因为自从我使用TableAdapters和DataSet以来已经很长时间了,但是不必设置DataRow.RowState = DataRowState.Modified;在TableAdapter意识到发生了什么之前? It''s just a guess as it''s a long time since I used TableAdapters and DataSets, but don''t you have to set DataRow.RowState = DataRowState.Modified; before the TableAdapter realises what''s going on?

我意识到这是一个非常老的问题,但这是以后的参考答案:请勿在之前调用AcceptCancel()更新()!它将标记该行为未更改,并且显然不会被更新.我同意MS文档对此有些困惑. 可变 I realize this is a very old question, but here is the answer for future reference: do NOT call AcceptCancel() before Update()! It will mark the row as Unchanged, and obviously it will not be updated. I agree that the MS documentation is somewhat confusing on this. Vasile

我有一个类似的问题,但是,我也无法向数据库添加行.我可以向数据集的表添加一行,但是tableadapter.update不会将更改提交到数据库.同时,tableadapter.insert确实可以工作,即在数据库中出现新行. I have a similar issue, however, I also cannot add rows to database. I can add a row to dataset''s table but tableadapter.update does not commit the changes to the database. At the same time tableadapter.insert does work though, i.e. new rows appear in database.

更多推荐

TableAdapter.Update不提交

本文发布于:2023-10-26 21:46:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531440.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TableAdapter   Update

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!