0

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
2
Contributors
8
Replies
26
Views
2 Years
Discussion Span
Last Post by Xiao_1
1

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

0

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"
0

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

0
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.    
0

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?

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.