when Register in this also will record the time in to access also is this code corrct

this my code

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        lbltime.Text = "Time:" + TimeString

        If String.IsNullOrWhiteSpace(txtadmno.Text) Or String.IsNullOrWhiteSpace(txtcard.Text) Then
            'MessageBox.Show("Please complete the on the box.", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If

      Using conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb")


            lbltime.Text = TimeOfDay.Hour & ":" & TimeOfDay.Minute & ":" & TimeOfDay.Second
            If TimeOfDay.Second < 10 Then
                Dim fitsecond As String
                fitsecond = TimeOfDay.Second
                lbltime.Text = TimeOfDay.Hour & ":" & TimeOfDay.Minute & ":" & "0" & fitsecond
            End If
            If TimeOfDay.Minute < 10 Then
                Dim fitminute As String
                fitminute = TimeOfDay.Minute
                lbltime.Text = TimeOfDay.Hour & ":" & "0" & fitminute & ":" & TimeOfDay.Second
            End If
            If TimeOfDay.Hour < 10 Then
                Dim fithour As String
                fithour = TimeOfDay.Hour
                lbltime.Text = "0" & fithour & ":" & TimeOfDay.Minute & ":" & TimeOfDay.Second
            End If

            Dim sql As String = "insert into tbl_studentadm (TimeIn, TimeOut) WHEN ([Stud Admin], [Admin Card]) = '" & txtadmno.Text & "' AND = '" & txtcard.Text & "'"
            Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql, Conn)
            sqlCom.Connection = Conn
            conn.Open()

            Dim result As Integer = sqlCom.ExecuteNonQuery()

            sqlCom.Dispose()
            Conn.Close()

            If result > 0 Then
                MessageBox.Show("Insert time in.")
            Else
                MessageBox.Show("Failure to time in.")

            End If
        End Using

Edited 1 Year Ago by Xiao_1

When you do an INSERT you must supply values. For example

INSERT INTO mytable (fld1, fld2, fld3)
       VALUES(fldvalue1, fldvalue2, fldvalue3)

You must supply data for all NOT NULL fields. I suspect what you are trying to do is an UPDATE which would look like

UPDATE mytable
   SET fld1 = fld1value, fld2 = fld2value
 WHERE fld3 = fld3value

when is not an sql keyword used with t-sql insert.
The only reference to insert & when is pl/sql and then the syntax is "insert when"

This article has been dead for over six months. Start a new discussion instead.