数据库更改后如何保存DataSet? [英] how to save the DataSet after making changes to the database?

查看:186
本文介绍了数据库更改后如何保存DataSet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个名为myDs的DataSet,并且通过直接访问在一个循环中编辑一个字段,如下所示:

  for(int i = 0; i< myDS.Tables [TableName] .Rows.Count; i ++)
{

//某些函数或web方法获取id值记录正在更新
int n = getNewNumber();

//根据一些条件更新数据集记录
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;
}
}

我如何在数据库中完成这些更改,可以在GridView中看到它,当我做databind()但数据库不受影响,我尝试使用fill& OdbcDataAdapter和OdbcCommandBuilder的更新方法?

解决方案

尝试本文所示的TableAdapter.Update过程:如何:更新数据库中的记录



此外,请确保您不仅需要访问要连接到的数据库,还可以更新所需表中的记录的权限。您可能有一个SQL Server配置问题,阻止您的代码更新。


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?

解决方案

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.

这篇关于数据库更改后如何保存DataSet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆