Share: C # About Update Database by DataGrid

xiaoxiao2021-03-06  58

His prawn! I have just been in contact with C # .NET, I have been using Delphi to develop. Sudden transformation is very uncomfortable. These two days have studied how to update the database record through DataGrid, a little harvest, here I put my method Post it, you have a prawn ax! Thank you! // ******************************************************************************************************************* ********************************* Private void updateFromDataGrid () {String Update_sql = ""

// Start Update System.Data.SqlClient.sqlConnection CONN_UPDATE = New SqlConnection (); conn_update.close (); conn_update.connectionstring = conn_Upd; conn_update.Open ();

System.Data.sqlclient.sqlcommand comm_update = new sqlcommand (); comm_update.connection = conn_update;

System.data.sqlclient.sqldataadapter Da_UPDATE = New SqldataAdapter (); Da_UPDATE.UPDATECOMMAND = Comm_update;

// Traverse all data of DataGrid and modify for (int i = 0; i <= DataGrid1.visibleRowCount-2; i ) {update_sql = "update client_manage set client_name = '" DataGrid1 [i, 1] .tostring () " ', Client_phone =' " DataGrid1 [i, 2] .tostring () " " " DATAGRID1 [I, 3] .tostring () "'Where client_id =" DataGrid1 [i, 0] .Tostring (); Comm_update.commandtext = update_sql; comm_update.executenon query ();

// Close the connection to save network resources conn_update.close ();

转载请注明原文地址:https://www.9cbs.com/read-82225.html

New Post(0)