hi,
pls help me how to generate crystal reports in asp.net using vb.net
database is sql server..
any internet sites..

Hi..

I try to help u

Dim FileName As String = ""
    Dim ErrorMessage As String
    Dim ExportToExcel As String = "0" 
    Dim Folder As String = ""

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Request.QueryString("ExportToExcel") Is Nothing Then ExportToExcel = Request.QueryString("ExportToExcel")
        If Not Request.QueryString("DataOnly") Is Nothing Then DataOnly = Request.QueryString("DataOnly")
        If Not Request.QueryString("folder") Is Nothing Then Folder = Request.QueryString("folder").Trim

        FileName = Request.QueryString("FileName")
        If FileName = "" Then Response.Redirect("../Others/Sorry.aspx?ErrorMessage=File is not found !")
        If Not IsPostBack Then
             ConfigureCrsytalReports()
            ExportReport()
        End If
    End Sub

 Sub SetDBLogonForReport()
        Dim Table As CrystalDecisions.CrystalReports.Engine.Table
        For Each Table In Crs.ReportDocument.Database.Tables
            Dim Logon As CrystalDecisions.Shared.TableLogOnInfo
            Logon = Table.LogOnInfo
            Logon.ConnectionInfo.ServerName = ConfigurationManager.AppSettings("Server").Trim
            Logon.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings("Database").Trim
            Logon.ConnectionInfo.Password = ConfigurationManager.AppSettings("Password").Trim 'Security.Decryp_Pwd(ConfigurationManager.AppSettings("Password").Trim)
            Logon.ConnectionInfo.UserID = ConfigurationManager.AppSettings("UID").Trim
            Table.ApplyLogOnInfo(Logon)
        Next
    End Sub

 Sub ExportReport()
        Dim WebMainFolder As String = Request.PhysicalApplicationPath
        Dim PdfFolder As String = ""
        Dim PdfFile As String = ""
      
            PdfFolder = WebMainFolder & "Pdf\"
            If ExportToExcel.Trim = "1" Then
                PdfFile = "\" & Session("UserId") & "-" & Replace(FileName.ToLower, ".rpt", ".xls")            
                If DataOnly = "1" Then
                    Crs.ReportDocument.ExportToDisk(ExportFormatType.ExcelRecord, PdfFolder & PdfFile)
                Else
                    Crs.ReportDocument.ExportToDisk(ExportFormatType.Excel, PdfFolder & PdfFile)
                End If
            Else
                PdfFile = Session("UserId") & "-" & Replace(FileName.ToLower, ".rpt", ".pdf")                
                Crs.ReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, PdfFolder & PdfFile)
            End If
            Response.Redirect(Request.ApplicationPath & "\Pdf\" & PdfFile, True)
    End Sub

 Sub ConfigureCrsytalReports()
        If Folder <> "" Then
            Crs.Report.FileName = Folder & "\" & FileName
        Else
            Crs.Report.FileName = FileName
        End If

            SetDBLogonForReport()
            If IsDBNull(Session("RecordSelection")) = False Then
                If Session("RecordSelection") <> "" Then
                    Crs.ReportDocument.RecordSelectionFormula = Trim(Session("RecordSelection"))
                Else
                    Crs.ReportDocument.RecordSelectionFormula = ""
                End If
            End If
        Crs.ReportDocument.Refresh() 
 
    End Sub

and put these controls in aspx form

<CR:CrystalReportSource ID="Crs" runat="server">
        </CR:CrystalReportSource>    
        <CR:CrystalReportViewer ID="Crv" runat="server" AutodataBind="true" HasRefreshButton="True" ReportSourceID="Crs" HyperlinkTarget="_new" HasCrystalLogo="False" ToolbarStyle-BackColor="#C0FFFF" ToolbarStyle-BorderColor="White" DisplayGroupTree="False" EnableDrillDown="False" HasDrillUpButton="False" HasToggleGroupTreeButton="False" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.