/
Update.cs
161 lines (133 loc) · 4.99 KB
/
Update.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace Add_New_Books
{
public partial class Update : Form
{
public Update()
{
InitializeComponent();
label2.Hide();
comboBox2.Hide();
label3.Hide();
textBox1.Hide();
}
public void update(string query)
{
OleDbConnection connection = new OleDbConnection();
string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
string path = (System.IO.Path.GetDirectoryName(executable));
AppDomain.CurrentDomain.SetData("DataDirectory", path);
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/LMS.accdb";
OleDbCommand command;
command = connection.CreateCommand();
try
{
command.CommandText = query;
command.CommandType = CommandType.Text;
connection.Open();
//SqlCommand comm = new SqlCommand(query, connection);
command.ExecuteNonQuery();
}
catch (Exception)
{
}
finally
{
if (connection != null)
connection.Close();
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text == "Books") {
label2.Show();
comboBox2.Show();
label3.Show();
textBox1.Show();
comboBox2.Items[0] = "Book ID";
comboBox2.Items[1] = "Book Name";
comboBox2.Items[2] = "Book Author";
comboBox2.Items[3] = "ISBN";
comboBox2.Items[4] = "Available Quantity";
comboBox2.Items[5] = "Price";
comboBox2.Items[6] = "Edition";
comboBox2.Items[7] = "Category";
}
if(comboBox1.Text == "Members"){
label2.Show();
comboBox2.Show();
label3.Show();
textBox1.Show();
//comboBox2.Items = {"Member ID","Member Name","City","Contact Number","Join Date","Email"};
comboBox2.Items[0] = "Member ID";
comboBox2.Items[1] = "Member Name";
comboBox2.Items[2] = "City";
comboBox2.Items[3] = "Contact Number";
comboBox2.Items[4] = "Join Date";
comboBox2.Items[5] = "Email";
}
}
private void Update_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
String field = "sdsd";
if ( comboBox2.Text == "Book ID")
field = "Book_ID";
if ( comboBox2.Text == "Book Name")
field = "Book_title";
if ( comboBox2.Text == "Book Author")
field = "Book_Author";
if ( comboBox2.Text == "ISBN")
field = "ISBN";
if ( comboBox2.Text == "Available Quantity")
field = "Available_qty";
if ( comboBox2.Text == "Price")
field = "Price";
if ( comboBox2.Text == "Edition")
field = "Edition";
if (comboBox2.Text == "Category")
field = "Category";
if (comboBox2.Text == "Member ID")
field = "member_id";
if (comboBox2.Text == "Member Name")
field = "m_name";
if (comboBox2.Text == "City")
field = "city";
if (comboBox2.Text == "Contact Number")
field = "contact_no";
if (comboBox2.Text == "Join Date")
field = "join_date";
if (comboBox2.Text == "Email")
field = "email";
if (comboBox1.Text == "Members") {
string query = "update member set "+ field +" = '"+ textBox1.Text +"' where book_ID = "+ textBox2.Text +";";
update(query);
}
if (comboBox1.Text == "Books") {
string query = "update Books set " + field + " = '" + textBox1.Text + "' where book_ID = " + textBox2.Text + ";";
//string query = "update Books set Book_title='jsdnjsdnsjnd' where Book_ID = 101;";
update(query);
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form2 Main_menu = new Form2();
Main_menu.Show();
}
}
}