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?


基础教程推荐
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30