Using a C# DataGridView to update SQL tables? -
i'm making form in program contains datagridview. there specific buttons viewing different tables database, work fine. however, want able edit contents of tables , send changes database. on 'edit bookings' button press, datagridview's data source set data adapter connected sql statement:
select * bookings
this works fine; output shows table, , have lines:
admindatagrid.allowusertodeleterows = true; admindatagrid.allowusertoaddrows = true;
to allow editing in data grid. issue having updating input put data grid. if possible update table either on 'update button' press or when different button pressed, have tried using sqlcommandbuilder generate insert , update commands, calling dataadapter.update() think doing quite wrong. can run me through how achieve i'm looking achieve?
thanks in advance, michael.
in update button:
int id; string name; string address; (int = 0; <= admindatagrid.rows.count-1; i++) { id = int.parse(admindatagrid.rows[i].cells["id"].value); name = admindatagrid.rows[i].cells["name"].value.tostring(); address = admindatagrid.rows[i].cells["address"].value.tostring(); // write c# code update table using id, name , address. in first cycle of loop table update first row data of admindatagrid. }
Comments
Post a Comment