為什么參考微軟的例子也不能在水晶報表中顯示數据呢?
這個程序是WINFORM的程序,數据庫是mysql,我是想顯示出主從報表,
參考了微軟中文社區的李洪根的例子,http://www.microsoft.com/china/community/Column/26.mspx
但還是不能讀取出數据來,真是郁悶啊! 我用的是VB.NET2005
代碼如下:
Imports System.Data
Imports System.Data.odbc
Imports CrystalDecisions.CrystalReports.Engine
Public Class testViewer
Inherits System.Windows.Forms.Form
Dim tableMaster As New DataTable( "tablemaster ") '主表
Dim tabledetail As New DataTable( "tabledetail ") '從表
Dim oRpt As New testCrystalReport
Dim dsdataSet As New testDataset '建立數据集
Private Sub testViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String = "DRIVER={MySQL ODBC 3.51 driver}; SERVER=localhost;DATABASE=mybase;UID=myname;PASSWORD=sa;OPTION=3 "
Dim CN As New OdbcConnection(str)
CN.Open()
'讀取主表
Dim daOrders As New OdbcDataAdapter( "select * from tablemaster ", CN)
'讀取從表
Dim daDetails As New OdbcDataAdapter( "select * from tabledetail ", CN)
CN.Close()
daOrders.Fill(dsdataSet, "tableMaster ")
daDetails.Fill(dsdataSet, "tabledetail ")
'用以下的兩個msgbox可以顯示出主從錶的數据已經被讀取出來了
MsgBox(Me.dsdataSet.Tables( "tablemaster ").Rows(0).Item(0))
MsgBox(Me.dsdataSet.Tables( "tabledetail ").Rows(0)( "description "))
testCrystalReport1.SetDataSource(dsdataSet)
CrystalReportViewer1.ReportSource = testCrystalReport1
End Sub
End Class
' '但是程序運行后在程序的運行的水晶報表參看器中顯示的空白的,
水晶報表我是按照主從錶的主鍵來分組的,也沒有數据顯示出來,
用主報表中插入子報表的方法也試了,還是不行,真的很郁悶啊,
[解决办法]
http://blog.sqlsky.com/article.asp?id=355
水晶报表中的主从报表