Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. string wrongType = "This is not a date";
  2. command.Parameters.Add("@Date", SqlDbType.DateTime).Value = wrongType;
  3.  
  4. string wrongType = "This is not a date";
  5. DateTime rightTyped;
  6.  
  7. if(DateTime.TryParse(wrongType, out rightTyped))
  8. {
  9. command.Parameters.Add("@Date", SqlDbType.DateTime).Value = rightTyped;
  10. }
  11.  
  12. string wrongType = "This is not a date";
  13. DateTime date;
  14. if(DateTime.TryParse(wrongType, out date))
  15. {
  16. // staff when string converted
  17. }
  18.  
  19. string wrongType = "This is not a date";
  20.  
  21. DateTime rightType = ...
  22.  
  23. command.Parameters.Add("@Date", SqlDbType.DateTime).Value = rightType;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement