Mar 5, 2011

Simple report using Crystal Reporting Tool. Tutorial part - 1



10 comments:

Zac

Could you please post a VB version ?
I have Visual Studio 2010 and Crystal 2010

Any help with VB and not C would be great

Anonymous

You seem to have left out a step and i cant figure out what to do next. Where did the "SimpleReport.aspx" page come from?

Anonymous

Hi Tarun

Can we open multiple reports with single crystal
report viewer control ?

Is there any way to open a report without using crystal report viewer control.

Thanks,
Gaurav

Pierre

Salut

Comment peut on faire pour travailler avec les parametres dans le crystal report de VB 2010

Pierre

Pierre

Salut

How can I do to work with crystal report posted in VB 2010.

Help me please.

Pierre From Kinshasa / RDC

Anonymous

Hi

Anyone has the vb.net code for the above?

Thx

Evahn

Thanks for the tutorial!! Very useful!

I managed to get this translated and working into VB - just doublecheck the report file name and database connection string for your project:


Imports CrystalDecisions.CrystalReports.Engine, CrystalDecisions.Shared, System.Data, System.Data.SqlClient, System.Configuration

Public Class SampleReport

Inherits System.Web.UI.Page


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim rptDoc As ReportDocument = New ReportDocument
Dim ds As dsSample = New dsSample ' .xsd file name
Dim dt As DataTable = New DataTable()
' Just set the name of data table
dt.TableName = "Crystal Report Example"
dt = getAllOrders() ' This function is located below
ds.Tables(0).Merge(dt)
' Your .rpt file path will be below
rptDoc.Load(Server.MapPath("CrystalReport1.rpt"))
' set dataset to the report viewer.
rptDoc.SetDataSource(ds)
CrystalReportViewer1.ReportSource = rptDoc
End Sub


Public Function getAllOrders() As DataTable

' Connection string replcae 'databaseservername' with your db server name
Dim sqlCon As String = "User ID=sa;PWD=sa; server=servername;INITIAL CATALOG=SampleDB;PERSIST SECURITY INFO=FALSE;Connect Timeout=0"
Dim con As New SqlConnection(sqlCon)
Dim cmd As New SqlCommand()
Dim ds As New DataSet()

Try
con.Open()
' Stored procedure calling. It is already in sample db.
cmd.CommandText = "getAllOrders"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
Dim Adapter As New SqlDataAdapter(cmd)
Adapter.Fill(ds, "Users")
Catch ex As Exception
Throw ex
Finally
cmd.Dispose()
If (con.State <> ConnectionState.Closed) Then con.Close()
End Try
Return ds.Tables(0)
End Function

End Class

Anonymous

Hi there, i tried using the VB codes that you have provided and there isnt any error. However, when i tried to load the page it takes ages and nth seems to appear.. Can some one please help me?

emilios

If you please help me out. i have followed your instructions but when i paste the code, the page is loading for hours.
i tried running the stored procedure manually...
at cmd.CommandText = "getAllOrders"; it stacks.

string sqlCon = "User ID=sa;PWD=sa; server=USER-PC/SQLEXPRESS;INITIAL CATALOG=SampleDB;PERSIST SECURITY INFO=FALSE;Connect Timeout=0";
SqlConnection Con = new SqlConnection(sqlCon);
SqlCommand cmd = new SqlCommand();
DataSet ds = null;
SqlDataAdapter adapter;
try
{
Con.Open();
//Stored procedure calling. It is already in sample db.
cmd.CommandText = "getAllOrders";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = Con;
ds = new DataSet();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "Users");
}
catch (Exception ex)

Anonymous

Hi Tarun,

I appreciate your sharing knowledge and experience.

I face 2 problem that when I run your code, it generate an error: login fail for user sa. Please help me to fix it

Thanks
Phuoc

Post a Comment

Author Profile

Total Pageviews

Categories

Followers

 

Sponsors