in this form the stuednt record the time when login so that when they take attendance know that time they come in

this the 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) VALUES ([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 CMD As New System.Data.OleDb.OleDbCommand
            CMD.CommandText = "Update(tbl_studentadm) SET(TimeIn = [Stud Admin], TimeOut = [Admin Card]) WHERE(TimeIn = [Stud Admin], TimeOut = [Admin Card])"



            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

        'Catch ex As Exception
        'MessageBox.Show("Failed to connect to Database..", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        'End Try

Recommended Answers

All 8 Replies

Hi

Not 100% sure what you are trying to do but I did notice some errors in your SQL statements.

Your INSERT statement should look like:

INSERT INTO tbl_studentadm (TimeIn, TimeOut) VALUES ('" & txtadmno.Text & "', '" & txtcard.Text & "')"

Your update statement is also wrong but I am not sure what values you want to update it to and what values make up your WHERE criteria but the general syntax of an update statement is:

UPDATE TableName Set FieldName = Value, AnotherFieldName = Value WHERE FieldCriteria = CriteriaValue

HTH

is it look like this

Dim CMD As New System.Data.OleDb.OleDbCommand
            CMD.CommandText = "Update(tbl_studentadm) SET([Stud Admin] = Values, another [Stud Admin] = WHERE TimeIN = TimeOutValues"

Hi

If you only wish to update the Stud Admin field then it would be:

CMD.CommandText = "UPDATE tbl_studentadm SET [Stud Admin] = Values WHERE TimeIn = TimeOutValues"

Please bear in mind thought that it depends on the data type of Stud Admin and TimeIn. For example, if Stud Admin is a text field then Values would need to be enclosed in quotes ('Values').

Alternatively, consider using parameters:

CMD.CommandText = "UPDATE tbl_StudentAdm SET [Stud Admin] = @StudAdmin WHERE TimeIn = @TimeIn"

CMD.Parameters.AddWithValue("@StudAdmin", Values)
CMD.Parameters.AddWithValue("@TimeIn", TimeOutValues)

HTH

CMD.Parameters.AddWithValue("@StudAdmin", **Values**)
CMD.Parameters.AddWithValue("@TimeIn", **TimeOutValues**)





this have error
'Values' is not declared. It may be inaccessible due to its protection level.
'TimeOutValues' is not declared. It may be inaccessible due to its protection level.    

Do you have a variable or control called Values or TimeOutValues?

no

This is why you are getting the error 'Values' is not declared and the same with TimeOutValues.

Where will the values for @StudAdmin and @TimeIn come from?

i not sure but now ok

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.