对数据库进行更改后如何保存DataSet?
如果我有一个名为 myDs 的数据集,并且我通过直接访问循环来编辑其中的字段,如下所示:
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 中看到它,但数据库不受影响,我尝试使用 fill & OdbcDataAdapter 和 OdbcCommandBuilder 的更新方法?
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";
}
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试本文中所示的 TableAdapter.Update 过程: 如何:更新数据库中的记录。
另外,请确保您不仅拥有对尝试连接的数据库的必要访问权限,而且还拥有更新所需表中记录的权限。您可能存在 SQL Server 配置问题,导致代码无法更新。
Try the TableAdapter.Update process shown in this article: How to: Update Records in a Database.
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.
由于它是 odbc,因此您可以使用
OdbcDataAdapter
;然后致电:免责声明:就我个人而言,我从不使用 DataSet 来......任何事情。 YMMV。
Since it is odbc, you might use an
OdbcDataAdapter
; then call:disclaimer: personally, I never use DataSet for.... anything. YMMV.
您应该在循环后输入两行
You should type two line after loop