Guest User

Untitled

a guest
Aug 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. Update with column name by parameter
  2. DataTable dt = new DataTable();
  3.  
  4. // Here I fill my datatable
  5.  
  6. for (int i = 0; i < dt.Rows.Count; i++)
  7. {
  8. for (int j = 0; j < dt.Columns.Count; j++)
  9. {
  10. string columnsname = dt.Rows[i][dt.columns[j].toString()].toString();
  11. SqlCommand comando = new SqlCommand();
  12. comando.commandText = "UPDATE Sales.Store SET @columnname = @demographics where id = @id";
  13. comando.Parameters.Add(new SqlParameter("@columnname", columname));
  14. comando.Parameters.Add(new SqlParameter("@dados2", dados2));
  15. comando.ExecuteNonQuery();
  16. comando.Clear();
  17. comando.Dispose()
  18. }
  19. }
Add Comment
Please, Sign In to add comment