1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| using (SqlConnection connection = new SqlConnection("..."))
{
DataTable dataTable = new DataTable();
string command = "select id_planning, member from planning";
connection.Open();
SqlDataAdapter dataAdapter = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand(command, connection);
dataAdapter.SelectCommand = cmd;
// ça, je ne le réutilise pas donc je sais pas à quoi ça sert :'(
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
commandBuilder.GetDeleteCommand();
commandBuilder.GetInsertCommand();
commandBuilder.GetUpdateCommand();
dataAdapter.Fill(dataTable);
// update database
DataRow newRow = dataTable.NewRow();
newRow["member"] = "robert";
dataTable.Rows.Add(newRow);
dataTable.AcceptChanges();
dataAdapter.Update(dataTable);
} |
Partager