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
我无法从另一个表中检索id_no,mysql是我的数据库
End Sub
答案 0 :(得分:0)
写这个方式::
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