Advertisement
Guest User

Untitled

a guest
May 10th, 2017
98
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.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.  
  12. namespace login
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. string cs = @"server=162.253.224.12;user id=meisterc;database=meisterc_mybb598;persistsecurityinfo=True;";
  22.  
  23. private void button2_Click(object sender, EventArgs e)
  24. {
  25. this.Close();
  26. }
  27.  
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30. if (textBox1.Text == "" || textBox2.Text == "")
  31. {
  32. MessageBox.Show("Please provide Username and Password");
  33. return;
  34. }
  35. try
  36. {
  37. //Create SqlConnection
  38. SqlConnection con = new SqlConnection(cs);
  39. SqlCommand cmd = new SqlCommand("Select * from tbl_Login where UserName=@username and Password=@password", con);
  40. cmd.Parameters.AddWithValue("@username", textBox1.Text);
  41. cmd.Parameters.AddWithValue("@password", textBox2.Text);
  42. con.Open();
  43. SqlDataAdapter adapt = new SqlDataAdapter(cmd);
  44. DataSet ds = new DataSet();
  45. adapt.Fill(ds);
  46. con.Close();
  47. int count = ds.Tables[0].Rows.Count;
  48. //If count is equal to 1, than show frmMain form
  49. if (count == 1)
  50. {
  51. MessageBox.Show("Login Successful!");
  52. this.Hide();
  53. Main mm = new login.Main();
  54. mm.Show();
  55. }
  56. else
  57. {
  58. MessageBox.Show("Login Failed!");
  59. }
  60. }
  61. catch (Exception ex)
  62. {
  63. MessageBox.Show(ex.Message);
  64. }
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement