-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserDeletion.cs
125 lines (102 loc) · 3.65 KB
/
userDeletion.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using Oracle.ManagedDataAccess.Client;
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;
namespace Db_project
{
public partial class userDeletion : Form
{
OracleConnection con;
// Replace this connection string with your actual Oracle database connection string
private string connectionString = "User Id=TEST;Password=TEST123;Data Source=localhost:1521/xe;";
public userDeletion()
{
InitializeComponent();
con = new OracleConnection(connectionString);
}
private void userDeletion_Load(object sender, EventArgs e)
{
try
{
con.Open();
// Construct the SQL query to retrieve all users
string query = "SELECT * FROM USER_TABLE";
OracleCommand cmd = new OracleCommand(query, con);
OracleDataAdapter oda = new OracleDataAdapter(cmd);
DataTable dt = new DataTable();
oda.Fill(dt);
// Bind the data to the DataGridView
dataGridView1.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
finally
{
con.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
con.Open();
// Get the USER_ID from the TextBox
string userId = textBox1.Text;
// Construct the SQL query to delete the user with the specified USER_ID
string deleteQuery = $"DELETE FROM USER_TABLE WHERE USER_ID = '{userId}'";
OracleCommand deleteCmd = new OracleCommand(deleteQuery, con);
int rowsAffected = deleteCmd.ExecuteNonQuery();
if (rowsAffected > 0)
{
MessageBox.Show("User deleted successfully.");
}
else
{
MessageBox.Show("User not found or deletion failed.");
}
// Refresh the DataGridView after deletion
string refreshQuery = "SELECT * FROM USER_TABLE";
OracleDataAdapter refreshOda = new OracleDataAdapter(new OracleCommand(refreshQuery, con));
DataTable refreshDt = new DataTable();
refreshOda.Fill(refreshDt);
dataGridView1.DataSource = refreshDt;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
finally
{
con.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
// Call the userDeletion_Load method to refresh the data
userDeletion_Load(sender, e);
}
private void label2_Click(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void userDeletion_Load_1(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)//
{
}
}
}