Form1.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace konkurs
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void button3_Click(object sender, EventArgs e)
  20. {
  21. }
  22. public string constring = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=konkurs;Integrated Security=True";
  23. private void button2_Click(object sender, EventArgs e)
  24. {
  25. SqlConnection con = new SqlConnection(constring);
  26. SqlDataReader sqlReader = null;
  27. con.Open();
  28. SqlCommand command = new SqlCommand("Select * FROM [dbo].[Users] WHERE login = @login AND password = @password", con);
  29. command.Parameters.Add("@login", textBox1.Text);
  30. command.Parameters.Add("@password", textBox2.Text);
  31. try
  32. {
  33. sqlReader = command.ExecuteReader();
  34. while (sqlReader.Read())
  35. {
  36. Form2 fr2 = new Form2();
  37. fr2.Show();
  38. }
  39. }
  40. catch (Exception ex)
  41. {
  42. MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
  43. }
  44. finally
  45. {
  46. if (sqlReader != null)
  47. sqlReader.Close();
  48. }
  49. }
  50. }
  51. }