how to save the DataSet after making changes to the database?(更改数据库后如何保存DataSet?)
问题描述
如果我有一个名为 myDs 的数据集,并且我通过在如下循环中直接访问来编辑其中的一个字段:
if I have a DataSet called myDs and I edit a field in it by direct access in a loop like the following:
for (int i = 0; i < myDS.Tables[TableName].Rows.Count; i++)
{
//some function or web method to get the id value of the record being updated
int n = getNewNumber();
//updating the dataset record according to some condition
if (n == 0)
{
myDS.Tables[TableName].Rows[i]["id"] = n;
myDS.Tables[TableName].Rows[i]["description"] = "some data";
}
else
{
myDS.Tables[TableName].Rows[i]["id"] = n;
myDS.Tables[TableName].Rows[i]["description"] = "new data";
}
}
我如何在数据库中完成这些更改,因为我在执行 databind() 时可以在 GridView 中看到它,但数据库不受影响,我尝试使用填充 &OdbcDataAdapter 和 OdbcCommandBuilder 的更新方法?
How I make these changes done in the database as I could see it in the GridView when I do databind() but the database is not affected and I try using the fill & update methods of OdbcDataAdapter and OdbcCommandBuilder?
推荐答案
尝试本文所示的 TableAdapter.Update 过程:如何:更新数据库中的记录.
Try the TableAdapter.Update process shown in this article: How to: Update Records in a Database.
另外,请确保您不仅拥有对尝试连接的数据库的必要访问权限,而且还拥有更新所需表中记录的权限.您可能遇到阻止代码更新的 SQL Server 配置问题.
Also, please make sure you not only have the necessary access to the database you are trying to connect to, but also permission to update records in the desired table. You may have a SQL Server configuration problem that is preventing your code from updating.
这篇关于更改数据库后如何保存DataSet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更改数据库后如何保存DataSet?


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01