当查询长时间运行并且执行任何 UI 操作时,我的 Windows 应用程序进入“无响应状态”。所以我选择了线程概念。但是在 Thread.start() 方法中执行数据库操作时。它给出了诸如“Windows应用程序已停止工作”之类的错误
我的代码:
Dim Newthread As New Thread(AddressOf test)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CONNECT_STRING = "Provider=IBMDADB2.DB2COPY1;Password=pwd;Persist Security Info=True;User ID="";Data Source="";dbalias="";"
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
strSQL = "query"
Newthread.Start(strSQL)
End Sub
Function test(ByVal strSQL As String)
connection = New OleDbConnection(CON_STRING)
connection.Open()
Dim selectCMD As OleDbCommand = New OleDbCommand(strSQL, connection)
Dim custDA As OleDbDataAdapter = New OleDbDataAdapter
custDA.SelectCommand = selectCMD
selectCMD.CommandTimeout = 0
Dim custDS As DataSet = New DataSet()
custDA.Fill(custDS)
Dim chk As New DataGridViewCheckBoxColumn()
DataGridView1.Columns.Add(chk)
chk.HeaderText = "Select Row"
chk.Name = "Select row"
DataGridView1.DataSource = custDS.Tables(0)
DataGridView1.Refresh()
End Function
错误发生在“ custDA.Fill(custDS) ”行中
错误 - Windows 应用程序已停止工作
任何人都可以帮助我...