This is part 1 of 3STEP 1: Modify the clsDataLayer to Use a Two-Step Process1. Open Microsoft Visual Studio.NET.2. Click the ASP.NET project called PayrollSystem to open it.3. Open the clsDataLayer class.4. Modify the SavePersonnel() function so that instead of just doing a single SQL INSERT operation with all of the personnel data, it does an INSERT with only the FirstName and LastName, followed by an UPDATE to save the PayRate, StartDate, and EndDate into the new record. (This two-step approach is not really necessary here because we are dealing with only one table, tblPersonnel, but we are doing it to simulate a case with more complex processing requirements, in which we would need to insert or update data in more than one table or maybe even more than one database.) Find the following existing code in the SavePersonnel() function:// Add your comments here
strSQL =Insert into tblPersonnel +(FirstName, LastName, PayRate, StartDate, EndDate) values (+FirstName+, +LastName+, +PayRate+, +StartDate+, +EndDate+);// Add your comments here
command.CommandType=CommandType.Text;
command.CommandText= strSQL;// Add your comments here
command.ExecuteNonQuery();Modify it so that it reads as follows:// Add your comments here
strSQL =Insert into tblPersonnel +(FirstName, LastName) values (+FirstName+, +LastName+);// Add your comments here
command.CommandType=CommandType.Text;
command.CommandText= strSQL;// Add your comments here
command.ExecuteNonQuery();// Add your comments here
strSQL =Update tblPersonnel +Set PayRate=+PayRate+, +StartDate=’+StartDate+, +EndDate=’+EndDate+ +Where ID=(Select Max(ID) From tblPersonnel);// Add your comments here
command.CommandType=CommandType.Text;
command.CommandText= strSQL;// Add your comments here
command.ExecuteNonQuery();5. Set frmMain as the startup form and run the PayrollSystem Web application to test the changes. When valid data values are entered for a new employee, things should work exactly as they di
d previously. To test it, enter valid data for a new employee in frmPersonnel and click Submit. The frmPersonnelVerified form should be displayed with the entered data values and a message that the record was saved successfully. Click the View Personnel button and check that the new personnel record was indeed saved to the database and that all entered data values, including the PayRate, StartDate, and EndDate, were stored correctly. Close the browser window.Now run the PayrollSystem Web application again, but this time, enter some invalid data (a nonnumeric value) in the PayRate field to cause an error, like this:6. Now, when you click Submit, the frmPersonnelVerified form should display a message indicating that the record was notsaved:However, when you click on the View Personnel button to display the personnel records, you should see that an incomplete personnel record was in fact created, with missing values for the PayRate, StartDate, and EndDate fields.This occurred because the Insert statement succeeded but the following Update statement did not. We do not want to allow this to happen because we end up with incomplete or incorrect data in the database. If the Update statement fails, we want the Insert statement to be rolled back, or undone, so that we end up with no record at all. We will fix this by adding transaction code in the next step.STEP 2: Add Transaction Code7. In the clsDataLayer.cls class file, add code to the SavePersonnel() function to create a transaction object. Begin the transaction, commit the transaction if all database operations are successful, and roll back the transaction if any database operation fails. The following listing shows the complete SavePersonnel() function; the lines you will need to add are marked with ** NEW ** in the preceding comment and are shown in bold and underlined.// This function saves the personnel data
public static bool SavePersonnel(string Database, string FirstName, string LastName,
string PayRate, string StartDate, string EndDate)
{
bool recordSaved;// ** NEW ** Add your comments here
OleDbTransaction myTransaction = null;