-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
268 lines (232 loc) · 7.63 KB
/
Form1.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//step 1
using System.Data;
using System.Data.SqlClient;
namespace ado_practice
{
// DESKTOP-QGETDS4\SQLEXPRESS
public partial class Form1 : Form
{
//step 2
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
SqlDataReader dr;
DataTable dt;
DataSet ds;
// step 3
string s = "server=DESKTOP-QGETDS4\\SQLEXPRESS;initial catalog=ado;integrated security=true";
public Form1()
{
InitializeComponent();
}
private void pnlRegister_Paint(object sender, PaintEventArgs e)
{
}
private void lblRegName_Click(object sender, EventArgs e)
{
}
private void lnkRegister_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
pnlRegister.Visible = true;
pnlDelete.Visible = false;
pnlProcedure.Visible = false;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void btnShowAll_Click(object sender, EventArgs e)
{
//creating object for another page to load
showall s = new showall();
s.Show();
this.Hide();
}
private void txtDelName_TextChanged(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
pnlDelete.Visible =true;
pnlRegister.Visible = false;
pnlProcedure.Visible = false;
}
private void lnlProcedure_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
pnlProcedure.Visible = true;
pnlDelete.Visible = false;
pnlRegister.Visible = false;
}
private void btnRegSubmit_Click(object sender, EventArgs e)
{
//query to insert
try
{
con = new SqlConnection(s);
con.Open();
cmd = new SqlCommand("insert into register values(@name,@age,@dept,@college,@city)", con);
cmd.Parameters.AddWithValue("@name", txtRegName.Text);
cmd.Parameters.AddWithValue("@age", txtRegAge.Text);
cmd.Parameters.AddWithValue("@dept", txtRegDept.Text);
cmd.Parameters.AddWithValue("@college", txtRegCollege.Text);
cmd.Parameters.AddWithValue("@city", cmbRegCity.Text);
int res = cmd.ExecuteNonQuery();
if (res > 0)
{
MessageBox.Show("Inserted Successfully");
}
else
{
MessageBox.Show(" Not Inserted ");
}
}
catch(Exception ex )
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
//query to delete particular column
try
{
con = new SqlConnection(s);
con.Open();
cmd = new SqlCommand("delete from register where name=@name",con);
cmd.Parameters.AddWithValue("@name",txtDelName.Text);
int res = cmd.ExecuteNonQuery();
if (res > 0)
{
MessageBox.Show("Deleted Successfully");
}
else
{
MessageBox.Show(" Not Deleted ");
}
}
catch(Exception ex )
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
private void btnProInsert_Click(object sender, EventArgs e)
{
//procedure insert
try
{
con = new SqlConnection(s);
con.Open();
cmd = new SqlCommand("sp_insert", con);
cmd.CommandType = CommandType.StoredProcedure;//procedure
cmd.Parameters.AddWithValue("@name", txtRegName.Text);
cmd.Parameters.AddWithValue("@age", txtRegAge.Text);
cmd.Parameters.AddWithValue("@dept", txtRegDept.Text);
cmd.Parameters.AddWithValue("@college", txtRegCollege.Text);
cmd.Parameters.AddWithValue("@city", cmbRegCity.Text);
int res = cmd.ExecuteNonQuery();
if (res > 0)
{
MessageBox.Show("Inserted Successfully using procedure");
}
else
{
MessageBox.Show(" Not Inserted using procedure");
}
}
catch(Exception ex )
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
private void btnProDelete_Click(object sender, EventArgs e)
{
//procedure delete
try
{
con = new SqlConnection(s);
con.Open();
cmd = new SqlCommand("sp_delete", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name", txtDelName.Text);
int res = cmd.ExecuteNonQuery();
if (res > 0)
{
MessageBox.Show("Deleted Successfully using procedure");
}
else
{
MessageBox.Show(" Not Deleted using procedure");
}
}
catch(Exception ex )
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
private void btnProUpdate_Click(object sender, EventArgs e)
{
sp_update u = new sp_update();
u.Show();
this.Hide();
}
private void btnProSelect_Click(object sender, EventArgs e)
{
procedure pr = new procedure();
pr.Show();
this.Hide();
}
private void cmbRegCity_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
procedure p1 = new procedure();
p1.Show();
this.Hide();
}
private void btnTwoTable_Click(object sender, EventArgs e)
{
two_gridviewcs t = new two_gridviewcs();
t.Show();
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
tire_architecture t = new tire_architecture();
t.Show();
this.Hide();
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
update u = new update();
u.Show();
this.Hide();
}
}
}