简体   繁体   中英

Update Sql Table from datagridview c#

Hi I have a datagriview and I add it a data source of a sql table

 this.fletera_facturasTableAdapter.Fill(this.indarDataSet2.fletera_facturas);
        // TODO: This line of code loads data into the 'indarDataSet1.fletera_facturas' table. You can move, or remove it, as needed.

and in the event of keypres i want to update the changes to sql if the user press "Enter" key on cell this:

 private void update_sql(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)13)
        {
            fletera_facturasTableAdapter.Update(indarDataSet2.fletera_facturas);
        }
    }

i don't get any error but the sql table doesn't update

I find out the solution I just need to add this line

 private void update_sql(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)13)
    {
        fletera_facturasTableAdapter.Update(indarDataSet2.fletera_facturas);
        **indarDataSet2.fletera_facturas.AcceptChanges();**
    }
}

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