Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21127

Check if record exist then do UPDATE, if not, then do INSERT. vb 2010 ms access

$
0
0
Hi,

I would like to ask help. I am currently creating a time keeping system. My only problem right now is with regards to time-in and time-out of the employee.

If button timeinout is clicked, it should check if there is a data that has time in, if there is, it should do time out.
the fields under TKS table, (TechMID, FullName, DateIN, TimeIN, DateOUT, TimeOUT, TotalHours).



Private Sub btntimeinout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntimeinout.Click
Dim cmd As New OleDb.OleDbCommand


Dim TechMID As String
Dim FullName As String
Dim DateIN As String
Dim TimeIN As String
Dim DateOUT As String
Dim TimeOUT As String

TechMID = lbltmid.Text
FullName = lblfn.Text
DateIN = lbldate.Text
TimeIN = lbltime.Text
DateOUT = lbldate.Text
TimeOUT = lbltime.Text

try

Dim sql1 As String
Dim A As Integer

sql1 = "SELECT * FROM TKS WHERE TechMID = '" & TechMID & "' AND DateIN IS NULL"

Dim DA As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql1, cnn)
Dim DS As New DataSet
DA.Fill(DS, "TKS")
A = DS.Tables("TKS").Rows.Count

If A > 0 Then
cmd.CommandText = "INSERT INTO TKS([TechMID], [FullName], [DateIn], [TimeIn]) VALUES ('" & TechMID & "','" & FullName & "','" & DateIN & "','" & TimeIN & "')"
cmd.ExecuteNonQuery()
MessageBox.Show("Time In Successfully Added.")

Else


cmd.CommandText = "UPDATE TKS set [DateOUT] = '" & DateOUT & "', [TimeOut] = '" & TimeOUT & "' WHERE [TechMID] = '" & TechMID & "' AND [DateIN] IS NOT NULL"
cmd.ExecuteNonQuery()
MessageBox.Show("Time Out Successfully Added.")


End If

Catch ex As Exception

End Try

'close connection
cnn.Close()
End Sub

I am not sure how to do it. Please help me. I attached the project. Hoping for any help asap.

Viewing all articles
Browse latest Browse all 21127

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>