Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
0 Sergey Alexandrovich Kryukov 768
1 OriginalGriff 420
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,272
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2014
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