Modify Button problem

Sep 21 2009 8:22 AM
I have defined the definitions for both Save & Modify Button in a class called ConnectionClass.cs and in the forms i have called the function. what i want to do is that i want that the Save button should save the the data as well as it should also modify the data. Can we do something related to it. public void SaveEmployeeRecord(int employeeId, string employeeName, string employeeDept, string systemType, string serialNumber, string assetNumber) { try { dbConnection = new OleDbConnection(); dbConnection.ConnectionString = strConnectionString; dbConnection.Open(); dbCommand = new OleDbCommand(); dbCommand.Connection = dbConnection; dbCommand.CommandType = CommandType.Text; dbCommand.CommandText = "Insert Into tblemployee Values (" + employeeId + ",'" + employeeName + "','" + employeeDept + "','" + systemType + "','" + serialNumber + "','" + assetNumber + "')"; dbCommand.ExecuteNonQuery(); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } finally { connectionClose(); } } public void ModifyEmployeeRecord(int employeeId, string employeeName, string employeeDept, string systemType, string serialNumber, string assetNumber) { try { dbConnection = new OleDbConnection(); dbConnection.ConnectionString = strConnectionString; dbConnection.Open(); dbCommand = new OleDbCommand(); dbCommand.Connection = dbConnection; dbCommand.CommandType = CommandType.Text; dbCommand.CommandText = "UPDATE tblemployee SET tblemployee.employeeName = '" + employeeName + "', tblemployee.employeeDept = '" + employeeDept + "', tblemployee.systemType = '" + systemType + "', tblemployee.serialNumber = '" + serialNumber + "', tblemployee.assetNumber = '" + assetNumber + "' WHERE tblemployee.employeeId=" + employeeId + ";"; dbCommand.ExecuteNonQuery(); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } finally { connectionClose(); } } this is the coding in the connectionclass.cs form. private void btnmodify_Click(object sender, EventArgs e) { try { ConnectionClass l_ConnectionClass = new ConnectionClass(); employeeName = txtempname.Text; employeeDept = txtempdept.Text; serialNumber = txtserial.Text; assetNumber = txtasset.Text; SetEditState(true); PublicVariables.IsUpdate = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } this is from the main form and this is what i have done under modify button. private void btnsave_Click(object sender, EventArgs e) { try { ConnectionClass l_ConnectionClass = new ConnectionClass(); employeeId = l_ConnectionClass.generateID("select employeeId from [tblIdmaster]", "employeeId"); employeeName = txtempname.Text; employeeDept = txtempdept.Text; serialNumber = txtserial.Text; assetNumber = txtasset.Text; if (PublicVariables.IsUpdate) { //employeeId = l_ConnectionClass.generateID("select employeeId from [tblemployee]", "employeeId"); l_ConnectionClass.ModifyEmployeeRecord(employeeId, employeeName, employeeDept, systemType, serialNumber, assetNumber); MessageBox.Show("Data Modified.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { l_ConnectionClass.SaveEmployeeRecord(employeeId, employeeName, employeeDept, systemType, serialNumber, assetNumber); MessageBox.Show("Saved successfully.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } LoadGrid(); ClearFields(); txtempname.Focus(); SetEditState(false); } catch (Exception ex) { MessageBox.Show(ex.Message); } } this is what i have done under save button. public sealed class PublicVariables { public static Boolean CheckLoginFlag = false; public static short OSUserID = 0; public static string UserRole = ""; public static Boolean IsUpdate = false; this is the publicvariables definition.

Answers (1)