Private Sub btnIN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIN.Click
Dim dt As String
dt = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")
Dim strSQL As String
Dim intNumRows As Integer
sqlcon = New SqlConnection("Server=TOSHIBA-PC\SQLEXPRESS;Database=parking;Trusted_Connection=True;")
sqlcon.Open()
strSQL = "SELECT COUNT(*) FROM member WHERE CardSN = '" & txtSN2.Text & "'"
sqlcmd = New SqlCommand(strSQL, sqlcon)
intNumRows = sqlcmd.ExecuteScalar()
If intNumRows > 0 Then
ds = New DataSet
da = New SqlDataAdapter("INSERT INTO inout (CardSN,dtin) VALUES ('" & txtSN2.Text & "','" & dt & "');", sqlcon) 'บันทึกเวลาเมื่อกดปุ่ม เข้า
da.Fill(ds, "inout")
Call showdata2()
Else
MessageBox.Show("คุณไม่ได้เป็นสมาชิก")
End If
sqlcon.Close()
End Sub
โค้ดบันทึกเวลาออก Code (VB.NET)
Private Sub btnOUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOUT.Click
Dim dt As String
dt = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")
ds = New DataSet
da = New SqlDataAdapter("ALTER TABLE inout ADD CONSTRAINT chk_Time CHECK (CardSN='" & txtSN2.Text & "' AND dtout='')", sqlcon)
da = New SqlDataAdapter("UPDATE inout SET dtout='" & dt & "'WHERE CardSN='" & txtSN2.Text & "'", sqlcon)
da.Fill(ds, "inout")
Call showdata2()
End Sub