Click here to Skip to main content
12,452,066 members (28,452 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
Hi All,
How to show crystal reports in Visual Studio 2005?
I wrote this code for reports,entire code is working but i didn't get output.Please check my code once.

Code:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class _Default
Inherits System.Web.UI.Page
Dim con As SqlConnection
Dim da As New SqlDataAdapter
Dim ds As DataSet
Dim cmd As New SqlCommand
Protected Sub btnSingle_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSingle.Click
CrystalReportViewer1.Visible = True
con = New SqlConnection(ConfigurationManager.ConnectionStrings("dbcon").ToString())
con.Open()
Dim rptdoc As New ReportDocument
ds = New DataSet
cmd.CommandText = "sp_studentrec"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
cmd.Parameters.Add("@Sno", SqlDbType.Int).Value = txtsno.Text
da.SelectCommand = cmd
da.Fill(ds)
rptdoc.Load(Server.MapPath("CryStudentReport.rpt"))
rptdoc.SetDataSource(ds)
CrystalReportViewer1.ReportSource = rptdoc
con.Close()
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
CrystalReportViewer1.Visible = False
End Sub
End Class

Thanks & Regards
Hari
Posted 26-Dec-12 22:36pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I got solution:

con = New SqlConnection(ConfigurationManager.ConnectionStrings("dbcon").ToString())
           con.Open()
           Dim rptdoc As New ReportDocument
           Dim dt As New DataTable
           ds = New DataSet
           cmd.CommandText = "sp_studentrec"
           cmd.CommandType = CommandType.StoredProcedure
           cmd.Connection = con
           cmd.Parameters.Add("@Sno", SqlDbType.Int).Value = txtsno.Text
           da.SelectCommand = cmd
           da.Fill(ds)
           dt = ds.Tables(0)
           rptdoc.Load(Server.MapPath("CryStudentReport.rpt"))
           rptdoc.SetDataSource(dt)
           CrystalReportViewer1.ReportSource = rptdoc
           CrystalReportViewer1.Visible = True
           con.Close()
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100