Created
September 13, 2022 14:11
-
-
Save chenbojian/c276edd7559625d10eca31a4233e7751 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Update(DataRow newRow, string connStr, string tableName) | |
{ | |
using MySqlDataAdapter da = new MySqlDataAdapter( | |
$"select * from {tableName}", | |
connStr | |
); | |
da.UpdateCommand = new MySqlCommandBuilder(da).GetUpdateCommand(); | |
DataSet ds = new DataSet(); | |
da.Fill(ds); | |
var dataTable = ds.Tables[0]; | |
var dataRow = dataTable.AsEnumerable().Single(r => (int)r[0] == (int)newRow[0]); | |
for (int i = 1; i < dataTable.Columns.Count; i++) | |
{ | |
dataRow.SetField(i, newRow[i]); | |
} | |
da.Update(ds); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment