how to save the DataSet after making changes to the database?

TopDeveloper picture TopDeveloper · Aug 14, 2011 · Viewed 8.5k times · Source

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?

Answer

John Tobler picture John Tobler · Aug 15, 2011

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.