我正在使用Vb.Net 2010来开发具有水晶报告CRforVS_13_0的项目。我连接到sqlserver并使用以下步骤填充我的数据集。
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource
Imports System.Data
Public Class frmPrinTest
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnn As SqlConnection
Dim connectionString As String
Dim sql As String
Dim MyCommand As New SqlCommand
Dim myDA As New SqlDataAdapter
connectionString = "Data Source=.\SQLEXPRESS;Initial Catalog=stock;Persist Security Info=True;User ID=sa;Password=1234[enter image description here][1];"
cnn = New SqlConnection(connectionString)
sql = "select Icode,Iname from stockInvt"
MyCommand.Connection = cnn
MyCommand.CommandText = sql
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
Dim ds As New DataSet1
myDA.Fill(ds, "stockInvt")
Dim objRpt As New CrystalReport1
objRpt.SetDataSource(ds)
CrystalReportViewer1.ReportSource = objRpt
'CrystalReportViewer1.Refresh()
End Sub
End Class
但我无法在数据集中显示数据或在水晶报表中显示数据表。 我也按照这个链接。 CrystalReport_ADO_Dataset PDF 请帮帮我。
答案 0 :(得分:0)
您必须指定将使用的表水晶报告。因此,只需将代码从此objRpt.SetDataSource(ds)
更改为此objRpt.SetDataSource(ds.tables("stockInvt"))
或objRpt.SetDataSource(ds.tables(0))