读书人

毕业设计 们救命 关于时间段有关问

发布时间: 2012-04-06 12:22:24 作者: rapoo

毕业设计 大虾们救命 关于时间段问题
实现 每隔一段时间从数据库(ACCESS)中读取一条记录

举个例子: 实现每隔 5 分钟 从数据库中读取一条数据(直到读完)

大虾们帮我实现下 怎么每隔一段时间 取数据 (取数据我会)


大家帮帮忙!!!!!

最好写出代码

[解决办法]
Imports System.Data
Imports System.Data.OleDb ' 用Access数据库来演示

Public Class Form1

Dim conn As OleDbConnection
Dim comm As OleDbCommand
Dim dr As OleDbDataReader

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Timer1.Interval = 5000
Dim connectionString As String = "您的连接词 "
conn = New OleDbConnection(connectionString)
conn.Open()
comm = New OleDbCommand( "SELECT * FROM 表名 ", conn)
dr = comm.ExecuteReader
Me.Timer1.Enabled = True ' 开始计时
End Sub

' 每5秒读一次数据
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If dr.Read Then
MsgBox(dr.Item(0).ToString) ' 读到数据时用MsgBox显示这一条记录的第一项
Else
Me.Timer1.Enabled = False ' 直到没有符合条件的记录时停止继续读取
End If
End Sub
End Class
[解决办法]
1.时间的控制用timer控件就可以了.
2.每取一条数据:
(1)dim num as integer
(2)页面载入时:num = 0
(3)取一条数据:
Dim connStr As String = "连接数据库语句 "
Dim con As New OleDbConnection(connStr)
Dim SqlStr As String = "数据库查询语句 "
Dim da As New OleDbDataAdapter(SqlStr, con)
Dim ds As New DataSet
Try
con.Open()
da.Fill(ds)
For i = q To ds.Tables(0).Rows.Count Step 1
Dim str As String = ds.Tables(0).Rows(i)(0).ToString().Trim() '取第i行的第一列数据
q = i + 1
If q > ds.Tables(0).Rows.Count Then
Timer1.Enabled = False
End If
Exit For
End For
con.Close()
Catch ex As Exception
MsgBox(ex.ToString())
q = i + 1
End Try

读书人网 >VB Dotnet

热点推荐