.net 定时器Timer用法(Timeofday)

时间:2022-07-18 19:13:49
 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim sql As String
Dim dt As New DataTable
Time2
= "11:14:00" '设置定时的时间,24小时制 ,应该放在出事加载程序中
Timer1.Interval = 1000 '设置计时器每秒钟运行一次 ,应该放在出事加载程序中

Timer1.Enabled = True '计时器开始运行 ,应该放在出事加载程序中

Time1 = TimeOfDay() '获取当前时间
rownum.Text = Time1
If Time1 = Time2 Then
Dim age
If agetext.Text = "" Then
age
= 0
Else
age
= Val(agetext.Text)
End If
sql
= "select * from student where sid='" & xuehaotext.Text & "'"
conn
= connect_db()
rs
= New SqlDataAdapter(sql, conn)
'conn.Close()
rs.Fill(dt) '填充表
DataGridView1.DataSource = dt '将表中的数据显示到datagridView控件中,绑定数据
DataGridView1.Columns(0).HeaderText = "学号" '设置列名
DataGridView1.Columns(1).HeaderText = "姓名"
DataGridView1.Columns(
2).HeaderText = "年龄"
DataGridView1.Columns(
3).HeaderText = "成绩"
rownum.Text
= Str(DataGridView1.RowCount) '获取行数
xuehaotext.Text = DataGridView1.Rows(0).Cells(0).Value '获取datagridview中的某个值
nametext.Text = DataGridView1.Rows(0).Cells(1).Value
If (DataGridView1.Rows(0).Cells(2).Value = 0) Then
agetext.Text
= ""
Else
agetext.Text
= Str(DataGridView1.Rows(0).Cells(2).Value)
End If
If (DataGridView1.Rows(0).Cells(3).Value = 0) Then
scoretext.Text
= ""
Else
scoretext.Text
= Str(DataGridView1.Rows(0).Cells(3).Value)
End If
End If
End Sub