108 – Insert Statement Using Visual Basic Application for Managing Payroll System Module

Insert Statement using Visual Basic Application for Managing Payroll System Module

In our previous lesson we define the module for Managing Payroll System for SQL statement Insert, Update and Delete. We will now proceed with our application in Visual Basic. Our task here is to be able to add new employee, update its information and delete data which is not needed to be stored.

ow to our frmNewEmployee form and double click the save button. Add the following code below.

[vbnet]

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If btnSave.Text = “Save” Then
dosave()
Else
doUpdate()
End If
End Sub

[/vbnet]

As you have observed in our code we control the button by determining what text it contains. This is to define our procedure whether to execute Insert or Update.

Let us now define our dosave() sub procedure by adding a Public Sub in our class.

[vbnet]

Public Sub doSave()

DATEHIRED = Format(dtpDateHired.Value, “yyyy-MM-dd”)

If txtEmplD.Text = “” Then
ErrorProvider1.SetError(txtEmplD, “Please provide Employee ID Number.”)
Else
ErrorProvider1.SetError(txtEmplD, String.Empty)
If txtLastName.Text = “” Then
ErrorProvider1.SetError(txtLastName, “Please provide Last Name.”)
Else
ErrorProvider1.SetError(txtLastName, String.Empty)
If txtFirstName.Text = “” Then
ErrorProvider1.SetError(txtFirstName, “Please First Name.”)
Else
ErrorProvider1.SetError(txtFirstName, String.Empty)
If txtMiddleName.Text = “” Then
ErrorProvider1.SetError(txtMiddleName, “Please provide Middle Name.”)
Else
ErrorProvider1.SetError(txtMiddleName, String.Empty)

If rbFemale.Checked Then
empsex = “Female”
ElseIf rbMale.Checked Then
empsex = “Male”
End If

findthis(“select * from `tblemployee` where `EMPLOYEEID` =” & txtEmplD.Text & ” and `SCHOOLID` =” & SCHOOLIDNO & “”)
If DefaultResult() = True Then
MsgBox(“Employee ID number already exist.”)
Else
IsSuccessResult = saveInsert(“INSERT INTO `tblemployee` (`EMPLOYEEID`, `LASTNAME`, `FIRSTNAME`, `MIDDLENAME`, `EMPADDRESS`, `EMPCONTACTNO`, `EMPSTATUS`, `EMPSEX`, `SCHOOLID`, `DATEHIRED`, `DEPARTMENTID`, `NOOFDEPENDENTS`)” & _
” VALUES (” & txtEmplD.Text & “, ‘” & txtLastName.Text & “‘, ‘” & txtFirstName.Text & “‘, ‘” & txtMiddleName.Text & “‘,'” & txtAddress.Text & “‘,'” & txtContactNo.Text & “‘,'” & cbCivilStatus.Text & “‘,'” & empsex & “‘,” & SCHOOLIDNO & “,'” & DATEHIRED & “‘,” & cbdepartment.SelectedValue & “,” & txtNoDependents.Text & “)”)
If IsSuccessResult = True Then

Me.Close()

Else
MsgBox(ERRORPROCESS)
End If
End If
End If
End If
End If
End If
End Sub

[/vbnet]

As you have observe in our code we catch some error for blank data entry which is not accepted during the insert procedure. So you have to add ErrorProvider1 to our form. Next, is the definition of IsSuccessResult variable which will be declare in our module PayrollMod.vb as Boolean. The purpose for this to check our Insert Statement if it is successful or not See code below.

[vbnet]

Public IsSuccessResult As Boolean

[/vbnet]

We just call our saveInsert() sub procedure in our PayrollMod.vb Module and added the Insert statement. For me, using module in our procedure is the best algorithm because you have coded only once and we just have to change our Insert statement. Proceed now to our next lesson for the Update application.

If you have any questions or suggestions about Insert Statement Using Visual Basic Application, please feel free to contact me at our contact page.

Previous topic MySQL Insert, Update, Delete Statement for Managing Payroll System Module

Leave a Comment