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