Advertisement
Guest User

Untitled

a guest
Apr 21st, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. public static int Register(string login, string password)
  2. {
  3. SqlConnection sqlConn = new SqlConnection(connectionString());
  4. //File.WriteAllText(@"c:\a\b\debug.txt", LoginVariables.connectionString());
  5. int ID = 0;
  6. try
  7. {
  8. sqlConn.Open();
  9. SqlCommand cmd = new SqlCommand("SELECT ID_User FROM Users WHERE Login_user=@Name_profile AND Password_user=@Password_profile", sqlConn);
  10. cmd.Parameters.AddWithValue("@Name_profile", login);
  11. cmd.Parameters.AddWithValue("@Password_profile", password);
  12. //File.WriteAllText(@"c:\a\b\error.txt", command.CommandText);
  13. ID = (Int32)cmd.ExecuteScalar();
  14. Console.WriteLine("Podany uzytkownik istnieje już w bazie danych podaj inne hasło.");
  15.  
  16. }
  17. catch (System.NullReferenceException se)
  18. {
  19. SqlCommand command = new SqlCommand("INSERT INTO Users (Login_user, Password_user, Name) VALUES (@Name_profile, @Password_profile, @Name_profile)", sqlConn);
  20. command.Parameters.AddWithValue("@Name_profile", login);
  21. command.Parameters.AddWithValue("@Password_profile", password);
  22. command.ExecuteNonQuery();
  23. Console.WriteLine("Konto zostało utworzone. " + Environment.NewLine + "Login : " + login + Environment.NewLine + "Password : " + password);
  24. SqlCommand cmd = new SqlCommand("SELECT ID_User FROM Users WHERE Login_user=@Name_profile", sqlConn);
  25. cmd.Parameters.AddWithValue("@Name_profile", login);
  26. //File.WriteAllText(@"c:\a\b\error.txt", command.CommandText);
  27. ID = (Int32)cmd.ExecuteScalar();
  28. Console.WriteLine("ID: " + ID);
  29. }
  30. catch (System.Data.SqlClient.SqlException se)
  31. {
  32. }
  33. return ID;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement