简体   繁体   中英

Updating data from the DataGridView into the database in C#

This is how I populate my DataGridView in the form load event:

private void Form1_Load(object sender, EventArgs e)
{
    this.animalsTableAdapter.Fill(this.animalsDataSet.Animals);
}

After changes are made in the DataGridView, I would like to update the bounded database when a "Save" button is clicked, so I have tried this:

private void button3_Click(object sender, EventArgs e)
{
    this.animalsTableAdapter.Update(this.animalsDataSet.Animals);
}

It doesn't give any error message, but it doesn't work either, meaning the changes in the DataGridView are not reflected into the bounded database.

Any suggestions?

You have to recall binding method for gridview. Write this line just below the Update method.

 this.animalsTableAdapter.Fill(this.animalsDataSet.Animals);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM