Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. if (adminyes.Checked == true || adminno.Checked == true && textBox1.Text != null && textBox2.Text != null && textBox3.Text != null)
  2. {
  3. admin = "Yes";
  4.  
  5. if (mode == "a")
  6. {
  7. x = 0;
  8. connect.Close();
  9. connect.ConnectionString = inventorydb;
  10. connect.Open();
  11. sqlcommand.CommandText = "SELECT * FROM Users WHERE Username ='" +textBox2.Text+ "' Or User_ID ='" +textBox1.Text+ "' ";
  12. sqlcommand.Connection = connect;
  13. OleDbDataReader reader = sqlcommand.ExecuteReader();
  14. while (reader.Read())
  15. {
  16. x++;
  17. }
  18.  
  19. if (x != 0)
  20. {
  21. MessageBox.Show("", "",MessageBoxButtons.OK);
  22. }
  23. else
  24. {
  25. DialogResult res = MessageBox.Show("Are you sure?", "Save User", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  26.  
  27. if (DialogResult.Yes == res)
  28. {
  29. connect.Close();
  30. connect.ConnectionString = inventorydb;
  31. connect.Open();
  32. sqlcommand.CommandText = "INSERT INTO Users (User_ID, Username, Password, Admin) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "', '" + textBox3.Text + "', '" + admin + "') ";
  33. sqlcommand.Connection = connect;
  34. reader = sqlcommand.ExecuteReader();
  35. MessageBox.Show("Record(s) Saved", "Sample");
  36. }
  37.  
  38. reset();
  39. }
  40. }
  41. else if (mode == "e")
  42. {
  43. DialogResult res = MessageBox.Show("Are you sure?", "Update User", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  44.  
  45. if (DialogResult.Yes == res)
  46. {
  47. connect.Close();
  48. connect.ConnectionString = inventorydb;
  49. connect.Open();
  50. sqlcommand.CommandText = "UPDATE Users SET User_ID = '" + textBox1.Text + "', Username = '" + textBox2.Text + "', Password = '" + textBox3.Text + "',Admin = '" + admin + "' WHERE SerialID = '" + idholder + "' ";
  51. sqlcommand.Connection = connect;
  52. OleDbDataReader reader = sqlcommand.ExecuteReader();
  53. reader.Read();
  54. MessageBox.Show("Record(s) Updated", "Sample");
  55.  
  56. }
  57.  
  58. reset();
  59. }
  60. }
  61. else
  62. {
  63. MessageBox.Show("", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement