So I've been doing an Employees Attendance Management System using vb.net using a windows form and a mySQL for my database. I successfully inserted an employee into my database but can't seem to check his time in into my database. I have two tables in my database (tbl_attendance and tbl_employee) I've successfully inserted data in my employee table but not in my attendance table. I could really use a fresh new eye since I've been looking for my error for a very long time now and broke down and now I'm here LOL. Here are my codes:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
If txtEmployeeID.Text = "" Then
MessageBox.Show("Please enter Employee ID", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
reloadtext("SELECT * FROM tbl_employees WHERE EMPLOYEEID='" & txtEmployeeID.Text & "'")
If dt.Rows.Count > 0 Then
reloadtext("SELECT * FROM tbl_attendance WHERE EMPLOYEEID='" & txtEmployeeID.Text & "' AND LOGDATE='" & lblDate.Text & "' AND AM_STATUS='Time In' AND PM_STATUS='Time Out'")
If dt.Rows.Count > 0 Then
MessageBox.Show("You already have an attendance for today", "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
reloadtext("SELECT * FROM tbl_attendance WHERE EMPLOYEEID ='" & txtEmployeeID.Text & "' AND LOGDATE='" & lblDate.Text & "' AND AM_STATUS ='Time In'")
If dt.Rows.Count > 0 Then
updatelog("UPDATE tbl_attendance SET TIMEOUT='" & TimeOfDay & "', PM_STATUS='Time Out' WHERE EMPLOYEEID='" & txtEmployeeID.Text & "' AND LOGDATE='" & lblDate.Text & "'")
MessageBox.Show("Successfully Timed out", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
createlog("INSERT INTO tbl_attendance(EMPLOYEEID,LOGDATE,TIMEIN,AM_STATUS)VALUES('" & txtEmployeeID.Text & "','" & lblDate.Text & "','" & TimeOfDay & "','Time In')")
MessageBox.Show("Successfully Timed in", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Else
MessageBox.Show("Employee ID not found", "Not found", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End If
End If
Catch ex As Exception
End Try
End Sub
I have a problem on my line 18
[This are my functions and connections.]
Imports MySql.Data.MySqlClient
Module CRUDConnection
Public result As String
Public cmd As New MySqlCommand
Public da As New MySqlDataAdapter
Public dt As New DataTable
Public ds As New DataSet
Public Sub create(ByVal sql As String)
Try
conn.Open()
With cmd
.Connection = conn
.CommandText = sql
result = cmd.ExecuteNonQuery
If result = 0 Then
MessageBox.Show("Data failed to insert.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
MessageBox.Show("Data successfully inserted.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End With
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
Public Sub reload(ByVal sql As String, ByVal DTG As Object)
Try
conn.Open()
dt = New DataTable
With cmd
.Connection = conn
.CommandText = sql
End With
da.SelectCommand = cmd
da.Fill(dt)
DTG.DataSource = dt
Catch ex As Exception
Finally
conn.Close()
da.Dispose()
End Try
End Sub
Public Sub reloadtext(ByVal sql As String)
Try
conn.Open()
With cmd
.Connection = conn
.CommandText = sql
End With
dt = New DataTable
da = New MySqlDataAdapter(sql, conn)
da.Fill(dt)
Catch ex As Exception
Finally
conn.Close()
da.Dispose()
End Try
End Sub
Public Sub createlog(ByVal sql As String)
Try
conn.Open()
With cmd
.Connection = conn
.CommandText = sql
result = cmd.ExecuteNonQuery
End With
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
Public Sub updatelog(ByVal sql As String)
Try
conn.Open()
With cmd
.Connection = conn
.CommandText = sql
result = cmd.ExecuteNonQuery
End With
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
End Module
cant seem to insert the values into my tbl_attendance
I don't know what to do anymore. I can't seem to find that one comma. Thanks in advance!