public static void UpdateFieldValue(string tableName,int rowIndex,Dictionary<string,object> dic_column_value) { SqlConnection conn = ConnectDB(); string sql = "select * from " + tableName; SqlDataAdapter da = new SqlDataAdapter(sql, conn); SqlCommandBuilder scb = new SqlCommandBuilder(da); da.UpdateCommand = scb.GetUpdateCommand(); DataSet dataset = new DataSet(); da.Fill(dataset,tableName); //更新字段值 foreach(KeyValuePair<string,object> kvp in dic_column_value) { dataset.Tables[0].Rows[rowIndex][kvp.Key] = kvp.Value; } da.Update(dataset,tableName); conn.Close(); }
转载于:https://www.cnblogs.com/nora/p/8064212.html