Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int AddReader(string login, string password, string name, string surname, string city, string birthDate, string phoneNumber)
- {
- int readerID;
- string query = $"INSERT INTO Reader OUTPUT INSERTED.ID VALUES('{login}', '{password}', '{name}', '{surname}', @city, @birthDate, @phoneNumber)";
- using (SqlConnection connection = new SqlConnection(Program.ConnectionString))
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- connection.Open();
- if (city != null)
- command.Parameters.AddWithValue("@city", city);
- else
- command.Parameters.AddWithValue("@city", DBNull.Value);
- if (birthDate != null)
- command.Parameters.AddWithValue("@birthDate", birthDate);
- else
- command.Parameters.AddWithValue("@birthDate", DBNull.Value);
- if (phoneNumber != null)
- command.Parameters.AddWithValue("@phoneNumber", phoneNumber);
- else
- command.Parameters.AddWithValue("@phoneNumber", DBNull.Value);
- readerID = (int)command.ExecuteScalar();
- }
- return readerID;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement