我的问题是vb.net中的后台工作者不允许执行一行代码 这是代码:
Private _worker As BackgroundWorker
Public Sub startload(ByVal e As System.EventArgs)
_worker = New BackgroundWorker()
AddHandler _worker.DoWork, AddressOf WorkerDoWork
AddHandler _worker.RunWorkerCompleted, AddressOf WorkerCompleted
_worker.RunWorkerAsync()
End Sub
Public Sub WorkerDoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
objRpt = New CRBooks
con.ConnectionString = ConnStr.Connstring
Dim query As String = CreateSelectQueryAndParameters()
'if there is no item select, then exit from the method.
If Not query.Contains("Column") Then
MessageBox.Show("No selection to display!")
Return
End If
Try
Dim adapter As MySqlDataAdapter = New MySqlDataAdapter(query, con)
Dim Ds As Books = New Books
adapter.Fill(Ds, "Books")
objRpt.SetDataSource(Ds)
MsgBox(Ds.Tables(0).Rows(0).Item(0))
frmReports.CrystalReportViewer1.ReportSource = objRpt
Catch oleEx As MySqlException
MessageBox.Show(oleEx.Message)
Catch Ex As Exception
MessageBox.Show(Ex.Message)
End Try
End Sub
Private Sub WorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
Me.Close()
End Sub
frmReports.CrystalReportViewer1.ReportSource = objRpt这一行并没有执行但是当我试图断点时,编译器会运行该行,但不会执行。
答案 0 :(得分:0)
不幸的是,您已为水晶报表查看器指定了报表源,但要查看该报表查看器,您应该调用包含报表查看器的相应表单的show方法来查看该报表。
使用此代码。
Public Sub WorkerDoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
objRpt = New CRBooks
con.ConnectionString = ConnStr.Connstring
Dim query As String = CreateSelectQueryAndParameters()
'if there is no item select, then exit from the method.
If Not query.Contains("Column") Then
MessageBox.Show("No selection to display!")
Return
End If
Try
Dim adapter As MySqlDataAdapter = New MySqlDataAdapter(query, con)
Dim Ds As Books = New Books
adapter.Fill(Ds, "Books")
objRpt.SetDataSource(Ds)
MsgBox(Ds.Tables(0).Rows(0).Item(0))
frmReports.CrystalReportViewer1.ReportSource = objRpt
frmReports.CrystalReportViewer1.Refreshreport()
frmReports.show()
Catch oleEx As MySqlException
MessageBox.Show(oleEx.Message)
Catch Ex As Exception
MessageBox.Show(Ex.Message)
End Try
End Sub
此处frmReports.show
显示包含报告查看器的表单。