Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Wish to create new crystal report in vb.net?
anybody can help!
Posted

1 solution

Answer by me:

C# and vb crystal reports are same

Generate a Report using Crystal Reports in Visual Studio 2010[^]

will help u lot......

1st create one table in database.
2nd add dataset by right click on the project and add new item Dataset then one dataset will be added now add columns to dataset for that right click on the datatable add column ,add same no of column and same name of column as database have
3rd now import 3 namespaces crystalDesion.crystalReports.Engine,

and code is here

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


4)Have to give call to display report function,on load i have given a call
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Call DisplayReport()
End Sub
5)now function is here

Protected Sub DisplayReport()

//Connection string as trial is database name
Dim strConnection As String
strConnection = "Data Source=10.20.14.157\SQLEXPRESS; MultipleActiveResultSets = True; Initial Catalog=trial; User id=sa; Password=#tiger786;"

Using Cn As New SqlConnection(strConnection)

Try
Cn.Open()
//have to create object of ReportDocument,ReportDocument is build in class
Dim rpt As New ReportDocument
//rptDataset is object of dataset which u have already created above dataset1
Dim rptDataSet As New dataset1
//object of datatable same name as database have
Dim dtSA As New DataTable("tblCustomer")
//create one row
Dim drSA As Data.DataRow

rptDataSet.Tables.Add(dtSA)
//my table have 2 fields customerid,Name
dtSA.Columns.Add("customerid", GetType(Integer))
dtSA.Columns.Add("Name", GetType(String))

//select data
Dim cmdSelect As New SqlCommand
Dim rdrSelect As SqlDataReader
cmdSelect = New SqlCommand("SELECT * from tblCustomer", Cn)
rdrSelect = cmdSelect.ExecuteReader
If rdrSelect.HasRows Then
While (rdrSelect.Read)
drSA = dtSA.NewRow
drSA("customerid") = rdrSelect("customerid")
drSA("Name") = rdrSelect("Name")
dtSA.Rows.Add(drSA)
End While
End If
//bind data
rpt.Load(Server.MapPath("Reports/CrystalReport.rpt"))
rpt.SetDataSource(dtSA)
//have to add one crystal report viewer in design first drag and drop it in design and name is crystalReportViwer1

CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.Visible = True
CrystalReportViewer1.RefreshReport()
CrystalReportViewer1.DataBind()

Catch ex As Exception
End Try
End Using
End Sub
End Class
----
now run it!
All the best
All is here noting than that
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900