C# DataSet, DataAdapter -- How to change row state to invoke an INSERT?(C# DataSet、DataAdapter -- 如何更改行状态以调用 INSERT?)
问题描述
我正在尝试实现一个另存为"按钮来获取 DataSet 中的数据,该数据是 DataAdapter.Filled(),然后 INSERT 到数据库中.
I am trying to implement a "Save As" button to take the data in a DataSet that was DataAdapter.Filled(), and INSERT into the database.
DataSet 有 4 个表——1 个父表(单行表),3 个子表.具有外部级联删除/更新约束.我的意图是向用户询问新的主键(复杂),然后尝试告诉 DataAdapter 或 DataSet 将 4 个表中的所有行(以及后续的新行)标记为 DataRowState.Added;但是 DataRow.SetAdded() 抛出异常Can only SetAdded on DataRowState.Unchanged rows"
The DataSet has 4 tables -- 1 parent (single row table), 3 child. with foriegn cascade delete/update constraints. My intention is to ask the user for a new primary key (complex) and then try to tell the DataAdapter or DataSet to mark all the rows (and subsequent new ones) in the 4 tables as DataRowState.Added; But DataRow.SetAdded() throws exception "Can only SetAdded on DataRowState.Unchanged rows"
有人知道怎么做吗?也欢迎任何其他有效的另存为"方法.非常感谢.
Anyone has idea how to do it? Any other efficient methods to do a "Save As" is also welcomed. Many thanks.
以防万一,DataRelations 已经设置好了.正常的 INSERT、UPDATE、DELETE 和 SELECT 可以完美运行.
Just in case, DataRelations have already been set. Normal INSERT, UPDATE, DELETE and SELECT works perfectly.
推荐答案
也许这行得通
row.AcceptChanges(); // sets DataRowState.Unchanged
row.SetAdded();
这篇关于C# DataSet、DataAdapter -- 如何更改行状态以调用 INSERT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# DataSet、DataAdapter -- 如何更改行状态以调用 INSERT?


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01