-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelete.cs
62 lines (56 loc) · 1.9 KB
/
Delete.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Student_Registration_Form
{
public partial class Delete : Form
{
public Delete()
{
InitializeComponent();
}
SqlConnection connection;
SqlCommand command;
private void Delete_Load(object sender, EventArgs e)
{
connection = new SqlConnection("Data Source=DESKTOP-8254JNC;Initial Catalog=Student_Registration_Form;Integrated Security=True");
}
private void btn_Dele_Click(object sender, EventArgs e)
{
try
{
connection.Open();
command = new SqlCommand("Delete from Registration where Student_ID='" + txt_ID.Text + "' ", connection);
int i = command.ExecuteNonQuery();
if (i == 1)
MessageBox.Show("Data deleted successfully", "infromation", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Data cannot delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
connection.Close();
}
catch (SqlException)
{
MessageBox.Show("Data base error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
{
MessageBox.Show("Please Check Again ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btn_ClearDel_Click(object sender, EventArgs e)
{
txt_ID.Clear();
}
private void btn_ExitDel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}