p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Crystal Reports (http://p2p.wrox.com/forumdisplay.php?f=113)
-   -   push data to crystal report asp.net (http://p2p.wrox.com/showthread.php?t=23614)

ewood January 7th, 2005 02:54 PM

push data to crystal report asp.net
 
I am attempting to use the push model for a crystal report from a asp.net project.
I am having two problems. First when I attempt to use a sql command I am able to create the report
but when I attempt to push the data to it I get a login failed error. When I correct this I get the original
data that was used to format the report not the modified data that I am attempting to push to it.
Here is the code.

Sub BindReport2()
        Dim oRpt As New CrystalReport1

        Dim myConnection As New SqlClient.SqlConnection
        myConnection.ConnectionString = "Server=WOODS1;Database=WEB_TEST;User ID=WebRep;Password=webrep;Trusted_Connection=False "
        Dim MyCommand As New SqlClient.SqlCommand
        MyCommand.Connection = myConnection
        MyCommand.CommandText = "select fname, lname, address1, city, state " & _
                                "from T1, T2 " & _
                                "where T1.empid = T2.empid and state = 'New York' "

        MyCommand.CommandType = CommandType.Text
        Dim MyDA As New SqlClient.SqlDataAdapter
        MyDA.SelectCommand = MyCommand
        Dim myDS As New DataSet
        'This is our DataSet created at Design Time
        MyDA.Fill(myDS, "Command")
        'You have to use the same name as that of your Dataset that you created during design time


        'oRpt.Database.Tables.Item("Command").SetDataSourc e(myDS)
        ' This is the Crystal Report file created at Design Time
        oRpt.SetDataSource(myDS)
        ' Set the SetDataSource property of the Report to the Dataset
        CrystalReportViewer1.ReportSource = oRpt
        'oRpt.SetDatabaseLogon("user","password","server", "database")
        oRpt.SetDatabaseLogon("WebRep", "webrep", "WOODS1", "web_test")
        CrystalReportViewer1.RefreshReport()

        ' Set the Crystal Report Viewer's property to the oRpt Report object that we created
    End Sub

My Second issue is similar though involves using a dataset. I am able to push the data to the report if
my dataset only contains one table if it contains more than one I get no data returned to the report.
Here is the code.

    Sub BindRep()
        Dim oRpt As New CrystalReport2
        Dim myConnection As New SqlClient.SqlConnection
        myConnection.ConnectionString = "Server=WOODS1;Database=WEB_TEST;User ID=WebRep;Password=webrep;Trusted_Connection=False "

        Dim strSQL As String = "select fname, lname, address1, city, state " & _
                                "from T1, T2 " & _
                                "where T1.empid = T2.empid and state = 'New York' "


        Dim objAdapter As New SqlClient.SqlDataAdapter(strSQL, myConnection)

        Dim objDataSet As New Dataset1
        objAdapter.Fill(objDataSet, "T1, T2")

        oRpt.SetDataSource(objDataSet)
        ' Set the SetDataSource property of the Report to the Dataset
        CrystalReportViewer1.ReportSource = oRpt
    End Sub

I have been able with the above code using a dataset that contains only one table to push the correct data
to the report. Any help on this issue whould be greatly appreciated.



All times are GMT -4. The time now is 03:36 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.