该报告没有表格

时间:2011-09-13 04:17:27

标签: .net vb.net crystal-reports windows-forms-designer

Private Sub frmReportExpenses_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim objDatasetExpence As New dSetExpences   // dataset object named as dSetExpences
Dim objRptExpence As New rptExpences       // Crystal report object
Dim MyCommand As New OleDbCommand()
Dim MyConnection As OleDbConnection
Dim myDA As New OleDbDataAdapter()

Try
    Dim connstring As String = "D:\HMSProjects\SMS\SMS\bin\Debug\"
    MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connstring + "msautoconfig.mdb;")
    MyConnection.Open()
    MyCommand.Connection = MyConnection

    MyCommand.CommandText = "SELECT * FROM expences"
    MyCommand.CommandType = CommandType.Text
    myDA.SelectCommand = MyCommand

    myDA.Fill(objDatasetExpence, "expences")
    objRptExpence.SetDataSource(objDatasetExpence)   // error here (Report has no Table)
    CrystalReportViewer1.ReportSource = objRptExpence
Catch ex As Exception

End Try

Me.WindowState = FormWindowState.Maximized
End Sub
End Class

此代码显示错误"Report has no tables" 我想用实际的Access 2003数据库显示水晶报告。在项目中添加空白报告并尝试填充DataSet对象,以上代码中的任何建议或更正。

1 个答案:

答案 0 :(得分:1)

Ya,您将DataAdapter的值添加到数据集objDatasetExpence中名为"expences"的表中,并且您没有将报表对象的数据源指向数据集内的数据表。如下更改您的代码,然后重试

objRptExpence.SetDataSource(objDatasetExpence.Tables(0)) 
          (or)
objRptExpence.SetDataSource(objDatasetExpence.Tables("expences")) 

当您将数据源分配给报告的数据库字段时,同样的错误将出现“报告没有表”。请参见下图,还会看到下一个图像,其中我为报告分配了一个数据库字段,并且出现了同样的错误Setting Database Fields Actuall Error