2
votes

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim AM As String = "8:01:00 AM"
    Dim remarks As String

    If LblTime.Text >= AM Then
        remarks = "LATE"
    Else
        remarks = "ON TIME"

    End If
    Try
        With com
            .Connection = con
            .CommandText = "SELECT count(*) Searchflag from employees_records where id_no='" & Txtid.Text & "' and date like '" & LblDate.Text & "';"
        End With


        sql = "INSERT INTO attendance (id_no, am_in, am_remarks, date) VALUES (@id_no, @am_in, @am_remarks, @date)"
        com.Connection = con
        com.CommandText = sql

        com.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@id_no", Txtid.Text))
        com.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@am_in", LblTime.Text))
        com.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@am_remarks", remarks))
        com.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@date", LblDate.Text))


        com.ExecuteNonQuery()
        If remarks = "LATE" Then
            MessageBox.Show("Hurry up your Late")
        ElseIf remarks = "ON TIME" Then
            MessageBox.Show("Very good you come on time!")
        End If




    Catch ex As Exception


    End Try

i can't retrieve the id_no from another table mysql is my database

End Sub
1
You need to be way more specific than "I can't retrieve the id_no".Bjørn-Roger Kringsjå
id is string or integerpankeel
Where is stored this id_no that you want to retrieve? Your code above doesn't retrieve any id_no field instead uses a textbox as value to insert an id_no in a table. So you already know this value.Steve
id_no stored in another table which is in the employees_recordsChris Gee
@ChrisGee when you want to notify someone of your comment add the at sign and select its name. In this way a comment icon is displayed on destination user.Steve

1 Answers

0
votes

Write This Way::

Dim AM As String = "8:01:00 AM"
Dim remarks As String

If LblTime.Text >= AM Then
    remarks = "LATE"
Else
    remarks = "ON TIME"

End If
Try
    With com
        .Connection = con
        .CommandText = "SELECT count(*) Searchflag from employees_records where id_no=" & val(Txtid.Text) & " and date like '" & LblDate.Text & "';"
    End With


    sql = "INSERT INTO attendance (id_no, am_in, am_remarks, date) VALUES (@id_no, @am_in, @am_remarks, @date)"
    com.Connection = con
    com.CommandText = sql

    com.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@id_no", Txtid.Text))
    com.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@am_in", LblTime.Text))
    com.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@am_remarks", remarks))
    com.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@date", LblDate.Text))


    com.ExecuteNonQuery()
    If remarks = "LATE" Then
        MessageBox.Show("Hurry up your Late")
    ElseIf remarks = "ON TIME" Then
        MessageBox.Show("Very good you come on time!")
    End If




Catch ex As Exception


End Try

End Sub