Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void cmdAdd_Click_1(object sender, EventArgs e)
- {
- try
- {
- conn.Open();
- command.Connection = conn;
- command.CommandText = "insert into student values('" + this.txtID.Text + "','" + this.txtFname.Text + "','" + this.txtLname.Text + "','" + this.txtCourse.Text + "','" + this.txtYear.Text + "')";
- int result = command.ExecuteNonQuery();
- if (result > 0)
- MessageBox.Show("New record save");
- conn.Close();
- }
- catch (Exception exp)
- {
- MessageBox.Show("Id number already existing");
- cmdClear_Click_1(this, null);
- conn.Close();
- }
- }
- private void cmdClear_Click_1(object sender, EventArgs e)
- {
- txtCourse.Text = "";
- txtID.Text = "";
- txtYear.Text = "";
- txtFname.Text = "";
- txtLname.Text = "";
- }
- private void cmdUpdate_Click_1(object sender, EventArgs e)
- {
- try
- {
- conn.Open();
- command.Connection = conn;
- command.CommandText = "update student set Fname='" + this.txtFname.Text + "', Course='" + this.txtCourse.Text + "', Yr ='" + this.txtYear.Text + "' where StudID ='" + this.txtID.Text + "'";
- command.ExecuteNonQuery();
- MessageBox.Show("Record Updated");
- conn.Close();
- }
- catch (Exception exp)
- {
- MessageBox.Show(exp.ToString());
- cmdClear_Click_1(this, null);
- conn.Close();
- }
- }
- private void cmdDelete_Click_1(object sender, EventArgs e)
- {
- try
- {
- conn.Open();
- command.Connection = conn;
- command.CommandText = "delete from student where studid ='" + this.txtID.Text + "'";
- command.ExecuteNonQuery();
- MessageBox.Show("deleted");
- cmdClear_Click_1(this, null);
- conn.Close();
- }
- catch (Exception exp)
- {
- MessageBox.Show(exp.ToString());
- cmdClear_Click_1(this, null);
- conn.Close();
- }
- }
- private void cmdSearch_Click_1(object sender, EventArgs e)
- {
- conn.Open();
- command.Connection = conn;
- command.CommandText = "Select * from student where studid='" + txtID.Text + "'";
- OleDbDataReader result = command.ExecuteReader();
- if (result.HasRows == true)
- {
- result.Read();
- txtFname.Text = result.GetValue(1).ToString();
- txtLname.Text = result.GetValue(2).ToString();
- txtCourse.Text = result.GetValue(3).ToString();
- txtYear.Text = result.GetValue(4).ToString();
- }
- else
- MessageBox.Show("Id number does not exist.");
- conn.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement