I'm updating my database using this code. only id and attendance date is updated but the time(AM_TIME_IN etc...) is not updating. What could be wrong?
I'm using access and time(AM_TIME_IN etc...) datatype is shorttext
Dim a As String = Now.ToShortTimeString
If a.Contains("AM") Then
a = "AM"
Else
a = "PM"
End If
Dim datarow As Object
Dim dsx As New DataSet
Dim dtx As New DataTable
Dim dtz As DataTable = New DataTable
Dim addlog_today As Boolean = False
Dim daz As OleDbDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Try
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Open()
dsx.Tables.Add(dtx)
Dim da As New OleDbDataAdapter("Select * FROM Attendance where EMPID='" & emp.EMPID & "'and ATTENDANCEDATE='" & Now.ToShortDateString & "'", con)
da.Fill(dtx)
For Each datarow In dtx.Rows
attendancedate = datarow.Item(2).ToString
Next
If attendancedate = "" Then
Try
Dim dtxx As DataTable = New DataTable
Dim dx As OleDbDataAdapter = New OleDbDataAdapter("select * from Attendance", con)
dx.Fill(dtxx)
Dim r As DataRow = dtxx.NewRow
r(1) = emp.EMPID
r(2) = Now.ToShortDateString
r(3) = emp.Designation
dtxx.Rows.Add(r)
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(dx)
dx.Update(dtxx)
Catch ex As Exception
End Try
End If
If a = "AM" Then
ds.Tables.Add(dt)
Dim dax As New OleDbDataAdapter("Select AM_TIME_IN,AM_TIME_OUT FROM Attendance where EMPID='" & emp.EMPID & "'and ATTENDANCEDATE='" & Now.ToShortDateString & "'", con)
dax.Fill(dt)
For Each datarow In dt.Rows
timein = datarow.Item(0).ToString
timeout = datarow.item(1).ToString
Next
If timein = "" Then
Try
daz = New OleDbDataAdapter("Select * FROM Attendance where EMPID='" & emp.EMPID & "'and ATTENDANCEDATE='" & Now.ToShortDateString & "'", con)
daz.Fill(dtz)
dtz.Rows(0).BeginEdit()
dtz.Rows(0)(3) = Now.ToShortTimeString
dtz.Rows(0).EndEdit()
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(daz)
daz.Update(dtz)
con.Close()
Catch ex As Exception
End Try
ElseIf timeout = "" Then
Try
daz = New OleDbDataAdapter("Select * FROM Attendance where EMPID='" & emp.EMPID & "'and ATTENDANCEDATE='" & Now.ToShortDateString & "'", con)
daz.Fill(dtz)
dtz.Rows(0).BeginEdit()
dtz.Rows(0)(4) = Now.ToShortTimeString
dtz.Rows(0).EndEdit()
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(daz)
daz.Update(dtz)
con.Close()
Catch ex As Exception
End Try
End If
ElseIf a = "PM" Then
ds.Tables.Add(dt)
Dim dax As New OleDbDataAdapter("Select PM_TIME_IN,PM_TIME_OUT FROM Attendance where EMPID='" & emp.EMPID & "'and ATTENDANCEDATE='" & Now.ToShortDateString & "'", con)
dax.Fill(dt)
For Each datarow In dt.Rows
timein = datarow.Item(0).ToString
timeout = datarow.Item(1).ToString
Next
If timein = "" Then
Try
daz = New OleDbDataAdapter("Select * FROM FROM Attendance where EMPID='" & emp.EMPID & "'and ATTENDANCEDATE='" & Now.ToShortDateString & "'", con)
daz.Fill(dtz)
dtz.Rows(0).BeginEdit()
dtz.Rows(0)(5) = Now.ToShortTimeString
dtz.Rows(0).EndEdit()
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(daz)
daz.Update(dtz)
con.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
ElseIf timeout = "" Then
Try
daz = New OleDbDataAdapter("Select * FROM Attendance where EMPID='" & emp.EMPID & "'and ATTENDANCEDATE='" & Now.ToShortDateString & "'", con)
daz.Fill(dtz)
dtz.Rows(0).BeginEdit()
dtz.Rows(0)(6) = Now.ToShortTimeString
dtz.Rows(0).EndEdit()
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(daz)
daz.Update(dtz)
con.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If
End If
Catch ex As Exception
End Try