Advertisement
Guest User

how come my password does not work from my tsql server?

a guest
Jan 31st, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 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. namespace Editer12
  12. {
  13. public partial class Form2 : Form
  14. {
  15. public Form2()
  16. {
  17. InitializeComponent();
  18. }
  19. string cs = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename= C:\Program Files\Microsoft SQL Server\MSSQL11.SKILLAGEITDB2\MSSQL\DATA\Skillage.mdf;Integrated Security = True; Connect Timeout = 30";
  20. private void Form2_Load(object sender, EventArgs e)
  21. {
  22.  
  23.  
  24.  
  25.  
  26. }
  27.  
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30. if (UserName.Text == "" || Password.Text == "")
  31. {
  32. MessageBox.Show("ITS WRONG ALL WRONG");
  33. return;
  34. }
  35. try
  36. {
  37. SqlConnection cr = new SqlConnection(cs);
  38. SqlCommand cmd = new SqlCommand("select * from LoginForm where UserName=@username and Password=@password", cr);
  39. cmd.Parameters.AddWithValue("@username", UserName.Text);
  40. cmd.Parameters.AddWithValue("@password", Password.Text); cr.Open();
  41. SqlDataAdapter adapt = new SqlDataAdapter(cmd);
  42. DataSet ds = new DataSet();
  43. adapt.Fill(ds);
  44. cr.Close();
  45. int count = ds.Tables[0].Rows.Count;
  46. if (count == 1)
  47. {
  48. if (UserName.Text == "" || Password.Text == "")
  49.  
  50. {
  51. MessageBox.Show("Access GRANTED!!!!!!!!");
  52. this.Hide();
  53. Form1 fm = new Form1();
  54. fm.Show();
  55. }
  56. else
  57. {
  58. MessageBox.Show("ACCESS DENIED!!!!");
  59.  
  60. }
  61. }
  62. }
  63.  
  64. catch (Exception ex)
  65. {
  66. MessageBox.Show(ex.Message);
  67. }
  68.  
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement