简体   繁体   中英

How to update Table After Editing DataGridView Using C#?

I have a C# DataGridView . When the user makes changes on the cell, and clicks a button, who do I make those changes in the database?

DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommandBuilder scb = new SqlCommandBuilder(adapter); 
adapter.Update(dt);

You could simply look-up changes and iterate over them while you execute your own queries. Save datagridView into sql database

You could also fire your action on RowLeave event.

https://social.msdn.microsoft.com/Forums/en-US/5f8741dc-5874-46e7-8665-6bda3674bafd/datagridview-automatically-save-changesaddsdeletions-as-user-moves-from-row-to-row?forum=vbide

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