Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int Register(string login, string password)
- {
- SqlConnection sqlConn = new SqlConnection(connectionString());
- //File.WriteAllText(@"c:\a\b\debug.txt", LoginVariables.connectionString());
- int ID = 0;
- try
- {
- sqlConn.Open();
- SqlCommand cmd = new SqlCommand("SELECT ID_User FROM Users WHERE Login_user=@Name_profile AND Password_user=@Password_profile", sqlConn);
- cmd.Parameters.AddWithValue("@Name_profile", login);
- cmd.Parameters.AddWithValue("@Password_profile", password);
- //File.WriteAllText(@"c:\a\b\error.txt", command.CommandText);
- ID = (Int32)cmd.ExecuteScalar();
- Console.WriteLine("Podany uzytkownik istnieje już w bazie danych podaj inne hasło.");
- }
- catch (System.NullReferenceException se)
- {
- SqlCommand command = new SqlCommand("INSERT INTO Users (Login_user, Password_user, Name) VALUES (@Name_profile, @Password_profile, @Name_profile)", sqlConn);
- command.Parameters.AddWithValue("@Name_profile", login);
- command.Parameters.AddWithValue("@Password_profile", password);
- command.ExecuteNonQuery();
- Console.WriteLine("Konto zostało utworzone. " + Environment.NewLine + "Login : " + login + Environment.NewLine + "Password : " + password);
- SqlCommand cmd = new SqlCommand("SELECT ID_User FROM Users WHERE Login_user=@Name_profile", sqlConn);
- cmd.Parameters.AddWithValue("@Name_profile", login);
- //File.WriteAllText(@"c:\a\b\error.txt", command.CommandText);
- ID = (Int32)cmd.ExecuteScalar();
- Console.WriteLine("ID: " + ID);
- }
- catch (System.Data.SqlClient.SqlException se)
- {
- }
- return ID;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement