Help with crystal

  Hi,
I am trying to print direct to printer using crystal in vs. Here is part of my code.


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


oconn = New SqlConnection(sconnstr)

'oconn.Open()

Try

ocmd.Connection = oconn

ocmd.CommandText = "select user_id,user_name from users where user_id = 1"

ocmd.CommandType = CommandType.Text

oda.SelectCommand = ocmd

Dim ds As New DataSet1

oda.Fill(ds, "users")

 

orpt.SetDataSource(ds.Tables(0))

 

rap.Load("C:\Documents and Settings\username\My Documents\Visual Studio\Projects\crystal\WindowsApplication1\WindowsApplication1\CrystalReport1.rpt")

rap.PrintToPrinter(1, False, 0, 0)

 

Catch ex As Exception

MsgBox(ex.Message)

Finally

oconn.Close()

oconn = Nothing

ocmd = Nothing

oda = Nothing

orpt = Nothing

rap = Nothing

End Try

End Sub

When the button is clicked the page is printed only with the column headers. I checked my sql statement against the database and it returns 1 row. I checked to see if the dataset is populated using

MsgBox(ds.Tables(0).Rows(0).Item(1).ToString)

The dataset has the correct data. The dataset is an .xsd file created manually.

Any ideas

Thanks



Answer this question

Help with crystal

  • jcMud

    Hi,
    I got it to work using this

    orpt.SetDataSource(ds.Tables(0))

    orpt.PrintToPrinter(1, False, 0, 0)


    I removed the following lines

    rap.Load("C:\Documents and Settings\username\My Documents\Visual Studio\Projects\crystal\WindowsApplication1\WindowsApplication1\CrystalReport1.rpt")

    rap.PrintToPrinter(1, False, 0, 0)


    Would this cause any problems


  • Armand du Plessis

    Hello,

    Taking a quick look at your code, it looks like you are setting the datasource for orpt object and yet opening the report as rap object.  You would need to set the report document first and then set the datasource to that object.

    Here is a link to the walkthroughs for Visual Studio 2005 Beta 2 including one for connecting using ADO .NET datasets:

    http://www.businessobjects.com/global/pdf/dev_zone/cr_vs2005_walkthroughs.pdf

    Keith - Business Objects

  • Help with crystal