Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public static int AddReader(string login, string password, string name, string surname, string city, string birthDate, string phoneNumber)
  2. {
  3. int readerID;
  4. string query = $"INSERT INTO Reader OUTPUT INSERTED.ID VALUES('{login}', '{password}', '{name}', '{surname}', @city, @birthDate, @phoneNumber)";
  5.  
  6. using (SqlConnection connection = new SqlConnection(Program.ConnectionString))
  7. using (SqlCommand command = new SqlCommand(query, connection))
  8. {
  9. connection.Open();
  10.  
  11. if (city != null)
  12. command.Parameters.AddWithValue("@city", city);
  13. else
  14. command.Parameters.AddWithValue("@city", DBNull.Value);
  15.  
  16. if (birthDate != null)
  17. command.Parameters.AddWithValue("@birthDate", birthDate);
  18. else
  19. command.Parameters.AddWithValue("@birthDate", DBNull.Value);
  20.  
  21. if (phoneNumber != null)
  22. command.Parameters.AddWithValue("@phoneNumber", phoneNumber);
  23. else
  24. command.Parameters.AddWithValue("@phoneNumber", DBNull.Value);
  25.  
  26. readerID = (int)command.ExecuteScalar();
  27. }
  28.  
  29. return readerID;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement