Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. private void cmdAdd_Click_1(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. conn.Open();
  6. command.Connection = conn;
  7. command.CommandText = "insert into student values('" + this.txtID.Text + "','" + this.txtFname.Text + "','" + this.txtLname.Text + "','" + this.txtCourse.Text + "','" + this.txtYear.Text + "')";
  8. int result = command.ExecuteNonQuery();
  9. if (result > 0)
  10. MessageBox.Show("New record save");
  11. conn.Close();
  12. }
  13. catch (Exception exp)
  14. {
  15. MessageBox.Show("Id number already existing");
  16. cmdClear_Click_1(this, null);
  17. conn.Close();
  18. }
  19. }
  20.  
  21. private void cmdClear_Click_1(object sender, EventArgs e)
  22. {
  23. txtCourse.Text = "";
  24. txtID.Text = "";
  25. txtYear.Text = "";
  26. txtFname.Text = "";
  27. txtLname.Text = "";
  28. }
  29.  
  30. private void cmdUpdate_Click_1(object sender, EventArgs e)
  31. {
  32. try
  33. {
  34. conn.Open();
  35. command.Connection = conn;
  36. command.CommandText = "update student set Fname='" + this.txtFname.Text + "', Course='" + this.txtCourse.Text + "', Yr ='" + this.txtYear.Text + "' where StudID ='" + this.txtID.Text + "'";
  37. command.ExecuteNonQuery();
  38. MessageBox.Show("Record Updated");
  39. conn.Close();
  40. }
  41. catch (Exception exp)
  42. {
  43. MessageBox.Show(exp.ToString());
  44. cmdClear_Click_1(this, null);
  45. conn.Close();
  46. }
  47. }
  48.  
  49. private void cmdDelete_Click_1(object sender, EventArgs e)
  50. {
  51. try
  52. {
  53. conn.Open();
  54. command.Connection = conn;
  55. command.CommandText = "delete from student where studid ='" + this.txtID.Text + "'";
  56. command.ExecuteNonQuery();
  57. MessageBox.Show("deleted");
  58. cmdClear_Click_1(this, null);
  59. conn.Close();
  60. }
  61. catch (Exception exp)
  62. {
  63. MessageBox.Show(exp.ToString());
  64. cmdClear_Click_1(this, null);
  65. conn.Close();
  66. }
  67. }
  68.  
  69. private void cmdSearch_Click_1(object sender, EventArgs e)
  70. {
  71. conn.Open();
  72. command.Connection = conn;
  73. command.CommandText = "Select * from student where studid='" + txtID.Text + "'";
  74. OleDbDataReader result = command.ExecuteReader();
  75. if (result.HasRows == true)
  76. {
  77. result.Read();
  78. txtFname.Text = result.GetValue(1).ToString();
  79. txtLname.Text = result.GetValue(2).ToString();
  80. txtCourse.Text = result.GetValue(3).ToString();
  81. txtYear.Text = result.GetValue(4).ToString();
  82. }
  83. else
  84. MessageBox.Show("Id number does not exist.");
  85. conn.Close();
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement