Can someone please tell me what i am doing wrong with this code.

I have created a dataset and want to push that data into crystal reports.

Dim rpt As New CrystalReport1() 'The report you created.
        Dim myConnection As SqlConnection
        Dim MyCommand As New SqlCommand()
        Dim myDA As New SqlDataAdapter()
        Dim myDS As New DataSet2() 'The DataSet you created.

            myConnection = New SqlConnection("Data Source=localhost;Initial Catalog=maintsystem;Persist Security Info=True;User ID=mbish;Password=mbish")
            MyCommand.Connection = myConnection
            MyCommand.CommandText = "SELECT * FROM Hardware"
            MyCommand.CommandType = CommandType.Text
            myDA.SelectCommand = MyCommand

            myDA.Fill(myDS, "dataset2")
            CrystalReportViewer1.ReportSource = "c:\CrystalReport2.rpt"

        Catch Excep As Exception
            MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Recommended Answers

All 6 Replies

why You dont try directly from your project,

please see below.

Right click in Solution Explorer on Project name and click on ADD Item
Select from the Templete view names "Crystal Report"
In name field enter the name of report as example "TEST.rpt" and click ADD
In crystal report document panel, select Report Wizard
In expert panel select Standard and click OK
Expand the Create New Connection Folder
select data file
seletc your data type
Click Finish
the folder expands and shows the xtreme sample DataBase
Expand th Table node and select Table Required.
Double Click the Table to move table into selected Tables Panel
Click Next
Click Table fields to move fields into display panel
in the available fields panel under report fields select table field and click
click finish
Crystal report will be loaded and will appear in main window of Visual Studio

In your coding I think below command is missing after command type which updates the data


hi thanks for your reply, the reason i am doing it this was is when i do it the way you have suggested when i run the report it asks me for a username and password which i dont want.

unless someone knows how i can get the report to run without the username and password box.!!! please help

when you get the user name and password window click FINISH and you will go automtically to next step.

sorry without inserting the user name and password

I am not able put .REPORTSOURCE ; mean after Crystalreport1. ?

I there any reference which should be added ?

Private Sub RadioButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton2.Click
Dim oRpt As New Crystalreport1()
oRpt.Load(Application.StartupPath & "/Crystalreport1.rpt")
Form2.CrystalReportViewer1.ReportSource = oRpt
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.