帮忙看看,这样写为什么不行?SqlDataAdapter myCommand = new SqlDataAdapter("select * from table1",myConnection);
DataSet DS = new DataSet();
myCommand.Fill(DS,"table1");
CrystalReport1 oRpt = new CrystalReport1();
oRpt.SetDataSource(DS.Tables["table1"]);
CrystalReportViewer1.ReportSource = oRpt;

解决方案 »

  1.   

    给一个例子参考:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim sRptFile As String
            Dim oRpt As New ReportDocument ' create a reportDocument object first        'oRpt.Refresh() ' clear the old info
            getAuthorData()
            sRptFile = Server.MapPath("Report.rpt") ' assign the rpt file name , if in different directory , you must specify the absoluted URL
            oRpt.Load(sRptFile)
            oRpt.SetDataSource(getAuthorData)        CRViewer.ReportSource = oRpt
            'CrystalReportViewer1.DisplayGroupTree = False    End Sub    Private Function getAuthorData() As DataSet
            Dim oDS As New DataSet
            Dim oConn As New SqlConnection
            oConn.ConnectionString = "server=你的SERVER;database=pubs;user=sa;pwd=sa"
            oConn.Open()        Dim oCmd As New SqlCommand
            oCmd.CommandText = "select au_id,au_lname,au_fname,phone,address from authors"
            oCmd.CommandType = CommandType.Text
            oCmd.Connection = oConn        Dim oAdapter As New SqlDataAdapter(oCmd)        oAdapter.Fill(oDS)        oCmd.Dispose()
            oAdapter.Dispose()
            oConn.Close()
            oConn.Dispose()
            oDS.Tables(0).TableName = "authors_tbl" ' Note' the table name must the same as the table name you specify in the xsd file        Return oDS    End Function