VB2005中用多线程来获取数据到DATAGRIDVIEW控件
VB2005中用多线程来获取数据到DATAGRIDVIEW控件Sub 查询()
Dim command As New techbook.A_操作类
command.connstr = 网络数据库信息
command.公用查询类("无条件精确查询", "订单入库表", "", "", "", "", "", "", "upc", DGV1)
command.close()
End Sub
以上是获取数据的过程
以下是自定义类的代码:
Public Sub 公用查询类(ByVal 查询类型 As String, ByVal 表名 As String, ByVal 关键字1 As String, ByVal 关键字2 As String, ByVal 条件1 As String, ByVal 条件2 As String, ByVal 起始时间 As String, ByVal 结束时间 As String, ByVal 排序字段 As String, ByVal dgv As DataGridView)
open()
Select Case 查询类型
Case "无条件精确查询"
str = "select * from " & 表名 & " order by " & 排序字段
m_cmd = New SqlCommand(str, conn)
m_ada.SelectCommand = m_cmd
m_ds.Clear()
m_ada.Fill(m_ds, 表名)
dgv.DataSource = m_ds.Tables(表名)
Case "单条件精确查询"
str = "select * from " & 表名 & " where " & 关键字1 & " = '" & 条件1 & "' order by " & 排序字段
m_cmd = New SqlCommand(str, conn)
m_ada.SelectCommand = m_cmd
m_ds.Clear()
m_ada.Fill(m_ds, 表名)
dgv.DataSource = m_ds.Tables(表名)
Case "单条件模糊查询"
str = "select * from " & 表名 & " where " & 关键字1 & " like '%" & 条件1 & "%' order by " & 排序字段
m_cmd = New SqlCommand(str, conn)
m_ada.SelectCommand = m_cmd
m_ds.Clear()
m_ada.Fill(m_ds, 表名)
dgv.DataSource = m_ds.Tables(表名)
Case "双条件精确查询"
str = "select * from " & 表名 & " where " & 关键字1 & " = '" & 条件1 & "' and " & 关键字2 & " ='" & 条件2 & "' order by " & 排序字段
m_cmd = New SqlCommand(str, conn)
m_ada.SelectCommand = m_cmd
m_ds.Clear()
m_ada.Fill(m_ds, 表名)
dgv.DataSource = m_ds.Tables(表名)
End Select
以上程序代码在运行过程中会出现假死的现象,我想请高手教我如何使用多线程或者异步调用的方法来获取数据库中的数据