How trying to figure out how to use SqlDataAdapter.Update(DataTable) method using a parameterised query. How can I add the values to the command without iterating over the whole DataTable?
And how can I execute the SqlDataAdapter insert and update methods within a transaction?
What I have so far is the following:
internal void InsertUpdate(DataTable dt){
using(var con = new SqlConnection(ConnectionString)){
var sb = new StringBuilder();
sb.AppendLine("UPDATE myTable");
sb.AppendLine("SET prop1 = @p1, prop2 = qp2");
sb.AppendLine("WHERE id = @id");
var cmd = new SqlCommand(sb.ToString());
cmd.Parameters.AddWithValue("p1", ????);
cmd.Parameters.AddWithValue("p2", ????);
cmd.Parameters.AddWithValue("id", ????);
var adapter = new SqlDataAdapter(selectQuery, con);
adapter.UpdateCommand = cmd;
adapter.Update(dt);
}
}
Best Regards
Jay