public int InserIntoDeptInfoTable(AddDeptClass addDeptObj) { string ID = null; connection.Open(); string queryString = "SELECT Dept_ID FROM Dept_Info_Table WHERE Dept_ID=('" + addDeptObj.DeptID + "') "; SqlCommand cmd = new SqlCommand(queryString, connection); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { ID = reader["Dept_ID"].ToString(); } connection.Close(); if (ID == addDeptObj.DeptID) { return(0); } else { connection.Open(); string insertString = "INSERT INTO Dept_Info_Table VALUES('" + addDeptObj.DeptID + "', '" + addDeptObj.DeptName + "','" + addDeptObj.DeptFullName + "')"; SqlCommand command = new SqlCommand(insertString, connection); command.ExecuteNonQuery(); connection.Close(); return(1); } }
private void courseAddButton_Click(object sender, EventArgs e) { addDeptObj = new AddDeptClass(); addDeptObj.DeptID = deptIdTextBox.Text; addDeptObj.DeptName = deptNameTextBox.Text; addDeptObj.DeptFullName = deptFullNameTextBox.Text; if ((deptNameTextBox.Text == "") || (deptIdTextBox.Text == "")) { MessageBox.Show("Please Fill-Up all fields!!"); this.Update(); } else { gateways = new Gateway(); if (gateways.InserIntoDeptInfoTable(addDeptObj) == 1) { MessageBox.Show("Information Added Successfully!!!"); deptResetButton_Click(sender, e); } else { MessageBox.Show("Already Added this department!!!"); } } }
public void UpdateDeptInfoTable(AddDeptClass addDeptOb) { connection.Open(); string insertString = "UPDATE Dept_Info_Table SET Dept_Name='" + addDeptOb.DeptName + "',Dept_Full_Name='" + addDeptOb.DeptFullName + "' WHERE Dept_ID='" + addDeptOb.DeptID + "'"; SqlCommand command = new SqlCommand(insertString, connection); command.ExecuteNonQuery(); connection.Close(); }
private void deptUpdateButton_Click(object sender, EventArgs e) { gateways = new Gateway(); addDeptObj = new AddDeptClass(); addDeptObj.DeptID = deptIdTextBox.Text; addDeptObj.DeptName = deptNameTextBox.Text; addDeptObj.DeptFullName = deptFullNameTextBox.Text; if (deptIdTextBox.Text == "" || deptNameTextBox.Text == "") { MessageBox.Show("Could not Update!"); } else { gateways.UpdateDeptInfoTable(addDeptObj); MessageBox.Show("Information Updated Successfully!"); deptResetButton_Click(sender, e); } }