Guest User

Untitled

a guest
Dec 17th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16.  
  17. namespace login_sever
  18. {
  19. /// <summary>
  20. /// Interaction logic for LoginScreen.xaml
  21. /// </summary>
  22. public partial class LoginScreen : Window
  23. {
  24. public LoginScreen()
  25. {
  26. InitializeComponent();
  27. }
  28.  
  29. private void BtnSubmit_Click(object sender, RoutedEventArgs e)
  30. {
  31. SqlConnection sqlConnection = new SqlConnection(@"Data Source = NK-VOSTRO\SQLEXPRESS; Initial Catalog = Login Database; Integrated Security = True");
  32. try
  33. {
  34. if (sqlConnection.State == System.Data.ConnectionState.Closed)
  35. sqlConnection.Open();
  36. String query = "SELECT * FROM [dbo].[User] WHERE Username=@username AND Password=@password";
  37. SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
  38. // sqlCommand.CommandType = System.Data.CommandType.Text;
  39. sqlCommand.Parameters.AddWithValue("@username", SqlDbType.NVarChar).Value = txtUsername.Text;
  40. sqlCommand.Parameters.AddWithValue("@password", SqlDbType.NVarChar).Value = txtPassword.Text;
  41.  
  42. int count = Convert.ToInt32(sqlCommand.ExecuteScalar());
  43. if (count == 1)
  44. {
  45. MainWindow mainWindow = new MainWindow();
  46. mainWindow.Show();
  47. this.Close();
  48. }
  49. else
  50. {
  51. MessageBox.Show("Username or password incorrect.");
  52. this.Close();
  53. }
  54.  
  55.  
  56. }
  57. catch (Exception ex)
  58. {
  59. MessageBox.Show(ex.Message);
  60. }
  61. finally
  62. {
  63.  
  64. }
  65. }
  66. }
  67. }
Add Comment
Please, Sign In to add comment