Solved

Crystal Report Viewer display

Posted on 2007-03-27
3
1,432 Views
Last Modified: 2012-08-14
hi,
I have a form that generates a Crystal report, on the form I have a buttom that is name "Run Report" and what i want ti to do is to display in a new window my report with the options of outputing to different formats, page navigator, print options and so on. Those things are easy find in a tool called "Crystal Report viewer"

how can i achived this?

here is my code:
Form1
------------------------------------------------------------
Public Class Form1

    Private Sub cmdReprot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReprot.Click

        Tools.GenerateReport("Performance.rpt", "C:\Test\CrystalReportDemo\CrystalReportDemo\", "@series", txtParameter.Text)
    End Sub
End Class
------------------------------------------------------

and here is the actual sub that executes the report:
------------------------------------------------------
    Public Class Tools

    Public Shared Sub GenerateReport(ByVal strRptName As String, ByVal strExportPath As String, _
           ByVal strParamName As String, ByVal strParamValue As String)

        Dim crReportDocument As ReportDocument

        Dim pFieldDefs As ParameterFieldDefinitions
        Dim mypFieldDef As ParameterFieldDefinition
        Dim pVal As ParameterValues = New ParameterValues
        Dim pDiscreteVal As ParameterDiscreteValue = New ParameterDiscreteValue

        Try
            crReportDocument = New ReportDocument
            crReportDocument.Load("C:\Reports\" & strRptName)

            crReportDocument.SetDatabaseLogon("park", "park")
            pFieldDefs = crReportDocument.DataDefinition.ParameterFields
            pDiscreteVal.Value = strParamValue
            pVal.Add(pDiscreteVal)
            mypFieldDef = pFieldDefs(strParamName)
            mypFieldDef.ApplyCurrentValues(pVal)
            ' crReportDocument.ExportToDisk(ExportFormatType.RichText, strExportPath)
            'crReportDocument.PrintToPrinter(1, True, 1, 1)

        Catch ex As Exception
            Windows.Forms.MessageBox.Show(ex.Message)
        End Try

    End Sub
End Class

0
Comment
Question by:jsctechy
3 Comments
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
Comment Utility
hi  jsctechy,

Here is some code that I use with CR reports & viewing, etc.

You can most of the items that you need in it.

'FORM 1
Imports System.Windows.Forms
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared
Imports Microsoft.VisualBasic
Public Class frmCrDates
    Inherits System.Windows.Forms.Form
    Public sDBStartDate As String      'Start Date
    Public sDBEndDate As String        'End Date
    Public bErrorDate As Boolean       'Error Checker

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        Me.Top = 0
        Me.Left = 200
        Me.Height = 130
        bErrorDate = False
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        Catch Exp As NullReferenceException
            '    Bypass this error
        Catch Exp As Exception
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents GroupBox As System.Windows.Forms.GroupBox
    Friend WithEvents lblEnd As System.Windows.Forms.Label
    Friend WithEvents dtpEndDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents dtpStartDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents lblStart As System.Windows.Forms.Label
    Friend WithEvents ErrorDate As System.Windows.Forms.ErrorProvider
    Private WithEvents BtnCancel As System.Windows.Forms.Button
    Private WithEvents BtnOk As System.Windows.Forms.Button
    Public WithEvents crDateView As CrystalDecisions.Windows.Forms.CrystalReportViewer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox = New System.Windows.Forms.GroupBox
        Me.lblEnd = New System.Windows.Forms.Label
        Me.dtpEndDate = New System.Windows.Forms.DateTimePicker
        Me.dtpStartDate = New System.Windows.Forms.DateTimePicker
        Me.lblStart = New System.Windows.Forms.Label
        Me.BtnCancel = New System.Windows.Forms.Button
        Me.BtnOk = New System.Windows.Forms.Button
        Me.ErrorDate = New System.Windows.Forms.ErrorProvider
        Me.crDateView = New CrystalDecisions.Windows.Forms.CrystalReportViewer
        Me.GroupBox.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox
        '
        Me.GroupBox.Controls.Add(Me.lblEnd)
        Me.GroupBox.Controls.Add(Me.dtpEndDate)
        Me.GroupBox.Controls.Add(Me.dtpStartDate)
        Me.GroupBox.Controls.Add(Me.lblStart)
        Me.GroupBox.Controls.Add(Me.BtnCancel)
        Me.GroupBox.Controls.Add(Me.BtnOk)
        Me.GroupBox.Location = New System.Drawing.Point(21, 12)
        Me.GroupBox.Name = "GroupBox"
        Me.GroupBox.Size = New System.Drawing.Size(648, 76)
        Me.GroupBox.TabIndex = 9
        Me.GroupBox.TabStop = False
        '
        'lblEnd
        '
        Me.lblEnd.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblEnd.Location = New System.Drawing.Point(232, 16)
        Me.lblEnd.Name = "lblEnd"
        Me.lblEnd.Size = New System.Drawing.Size(84, 20)
        Me.lblEnd.TabIndex = 12
        Me.lblEnd.Text = "End Date:"
        '
        'dtpEndDate
        '
        Me.dtpEndDate.Location = New System.Drawing.Point(232, 40)
        Me.dtpEndDate.Name = "dtpEndDate"
        Me.dtpEndDate.Size = New System.Drawing.Size(196, 20)
        Me.dtpEndDate.TabIndex = 1
        '
        'dtpStartDate
        '
        Me.dtpStartDate.CustomFormat = ""
        Me.dtpStartDate.Location = New System.Drawing.Point(8, 40)
        Me.dtpStartDate.Name = "dtpStartDate"
        Me.dtpStartDate.Size = New System.Drawing.Size(196, 20)
        Me.dtpStartDate.TabIndex = 0
        '
        'lblStart
        '
        Me.lblStart.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblStart.Location = New System.Drawing.Point(8, 12)
        Me.lblStart.Name = "lblStart"
        Me.lblStart.Size = New System.Drawing.Size(84, 20)
        Me.lblStart.TabIndex = 9
        Me.lblStart.Text = "Start Date:"
        '
        'BtnCancel
        '
        Me.BtnCancel.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.BtnCancel.Location = New System.Drawing.Point(544, 29)
        Me.BtnCancel.Name = "BtnCancel"
        Me.BtnCancel.Size = New System.Drawing.Size(88, 28)
        Me.BtnCancel.TabIndex = 8
        Me.BtnCancel.Text = "&Cancel"
        '
        'BtnOk
        '
        Me.BtnOk.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.BtnOk.Location = New System.Drawing.Point(444, 29)
        Me.BtnOk.Name = "BtnOk"
        Me.BtnOk.Size = New System.Drawing.Size(88, 28)
        Me.BtnOk.TabIndex = 7
        Me.BtnOk.Text = "&Ok"
        '
        'ErrorDate
        '
        Me.ErrorDate.ContainerControl = Me
        '
        'crDateView
        '
        Me.crDateView.AccessibleName = ""
        Me.crDateView.ActiveViewIndex = -1
        Me.crDateView.Location = New System.Drawing.Point(0, 96)
        Me.crDateView.Name = "crDateView"
        Me.crDateView.ReportSource = Nothing
        Me.crDateView.Size = New System.Drawing.Size(688, 252)
        Me.crDateView.TabIndex = 10
        '
        'frmCrDates
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(688, 354)
        Me.Controls.Add(Me.crDateView)
        Me.Controls.Add(Me.GroupBox)
        Me.Name = "frmCrDates"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "Select Dates For Crystal Reports"
        Me.GroupBox.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
#Region "Pick Dates Controls"
    Private Sub dtpStartDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpStartDate.ValueChanged
        If dtpStartDate.Value > Now Then
            ErrorDate.SetError(dtpStartDate, "Start Date Must be less than or equal to Todays Date")
            bErrorDate = True
        Else
            ErrorDate.SetError(dtpStartDate, "")
            bErrorDate = False
        End If
    End Sub
    Private Sub dtpStartDate_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpStartDate.Leave
        dtpStartDate.Format = DateTimePickerFormat.Custom
        dtpStartDate.CustomFormat = "MM'/'dd'/'yyyy"   '"yyyy'-'MM'-'dd"    'Change format for SQL SERVER Dates
        sDBStartDate = dtpStartDate.Text
        dtpStartDate.Format = DateTimePickerFormat.Long
    End Sub
    Private Sub dtpstartDate_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpStartDate.LostFocus
        dtpEndDate.Format = DateTimePickerFormat.Custom
        dtpEndDate.CustomFormat = "MM'/'dd'/'yyyy" '"yyyy'-'MM'-'dd"        'Change format for SQL SERVER Dates
        sDBEndDate = dtpEndDate.Text
        dtpEndDate.Format = DateTimePickerFormat.Long
    End Sub
    Private Sub dtpEndDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpEndDate.ValueChanged
        If dtpEndDate.Value < dtpStartDate.Value Or dtpEndDate.Value > Now Then
            ErrorDate.SetError(dtpEndDate, "End Date Must be greater than or equal to Start Date or before todays date")
            bErrorDate = True
        Else
            ErrorDate.SetError(dtpEndDate, "")
            bErrorDate = False
        End If
    End Sub
    Private Sub dtpEndDate_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpEndDate.Leave
        dtpEndDate.Format = DateTimePickerFormat.Custom
        dtpEndDate.CustomFormat = "MM'/'dd'/'yyyy" '"yyyy'-'MM'-'dd"        'Change format for SQL SERVER Dates
        sDBEndDate = dtpEndDate.Text
        dtpEndDate.Format = DateTimePickerFormat.Long
    End Sub
    Private Sub dtpEndDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpEndDate.Click
        If dtpEndDate.Value < dtpStartDate.Value Or dtpEndDate.Value > Now Then
            ErrorDate.SetError(dtpEndDate, "End Date Must be greater than or equal to Start Date or before todays date")
            bErrorDate = True
        Else
            ErrorDate.SetError(dtpEndDate, "")
            bErrorDate = False
        End If
    End Sub

#End Region

    Private Sub BtnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOk.Click
        Cursor.Current = Cursors.WaitCursor
        If bErrorDate = True Then
            ErrorDate.BlinkStyle = ErrorBlinkStyle.AlwaysBlink
            ErrorDate.BlinkStyle = ErrorBlinkStyle.BlinkIfDifferentError.AlwaysBlink
            Exit Sub
        End If
        'Create an instance of the strongly typed report object.
        Dim myDBRpt As New ReportDocument

        GetReportConnection(myDBRpt)

        Try
            Parmas(myDBRpt)
            crDateView.DisplayGroupTree = False

            ' Set the report source for the crystal reports viewer to the
            ' report instance.
            crDateView.ReportSource = myDBRpt

            ' Zoom viewer to fit to the whole page so the user can see the report
            crDateView.Zoom(1) '1 is page width and 2 is view whole page)
            myReport = myDBRpt
        Catch Exp As LoadSaveReportException
            MsgBox("Incorrect path for loading report.", _
                    MsgBoxStyle.Critical, "Load Report Error")

        Catch Exp As Exception
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")

        End Try
        Me.Height = 424
        Cursor.Current = Cursors.Default
    End Sub
    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        MyBase.Close()
    End Sub
    Private Sub frmDates_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Me.crDateView.SetBounds(5, 100, Me.Width - 20, Me.Height - 140)
    End Sub
    Private Sub GetReportConnection(ByVal myDBRpt)
        ' Objects used to set the proper database connection information
        Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
        Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

        Try
            ' Load the report
            myDBRpt.Load(sAppPath & sReportPath & sReportName, CrystalDecisions.[Shared].OpenReportMethod.OpenReportByTempCopy)

            ' Set the connection information for all the tables used in the report
            For Each tbCurrent In myDBRpt.Database.Tables
                tliCurrent = tbCurrent.LogOnInfo
                With tliCurrent.ConnectionInfo
                    .ServerName = sDBServer
                    .UserID = sUSERid
                    .Password = ""
                    .DatabaseName = sDBName
                End With
                tbCurrent.ApplyLogOnInfo(tliCurrent)
            Next tbCurrent
        Catch Exp As LoadSaveReportException
            MsgBox("Incorrect path for loading report.", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message & "   in GetReportConnection Procedure", MsgBoxStyle.Critical, "General Error")

        End Try
    End Sub
    Public Sub Message(ByVal myReport)
        Dim myExpOpt As New ExportOptions
        Dim myFileDesOpt As New CrystalDecisions.Shared.DiskFileDestinationOptions
        Dim myFormatTypOpt As New CrystalDecisions.Shared.PdfRtfWordFormatOptions

        Try
            myFileDesOpt.DiskFileName = sAppPath & sReportPath & sReportDirPath(0) & "Test.pdf"
            myExpOpt = myReport.ExportOptions
            With myExpOpt
                .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
                .DestinationOptions = myFileDesOpt
                .FormatOptions = myFormatTypOpt
            End With
            MsgBox("Do you want to save the New Report?", MsgBoxStyle.OKCancel, "Save Report")
            If vbOK = MsgBoxResult.OK Then
                myReport.Export()
            Else
                Exit Sub
            End If
        Catch Exp As ExportException
            MsgBox("Incorrect path for saving report.", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message & "   in Message", MsgBoxStyle.Critical, "General Error")

        End Try
    End Sub
    Private Sub Parmas(ByVal myDBRpt) 'FOR Dates and Range
        ' Objects used to set the parameters in the report
        Dim pvCollection As New CrystalDecisions.Shared.ParameterValues
        Dim pdvStartName As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim pdvEndName As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim pdvRange As New CrystalDecisions.Shared.ParameterRangeValue

        Try
            '********************************* Start Date **********************************
            ' Set the discreet value to the Start Date.
            pdvStartName.Value = sDBStartDate
            ' Add it to the parameter collection.
            pvCollection.Add(pdvStartName)
            ' Apply the current parameter values.
            myDBRpt.DataDefinition.ParameterFields("Start Date").ApplyCurrentValues(pvCollection)

            '********************************* End Date **********************************
            ' Set the discreet value to the End Date.
            pdvEndName.Value = sDBEndDate
            ' Add it to the parameter collection.
            pvCollection.Add(pdvEndName)
            ' Apply the current parameter values.
            myDBRpt.DataDefinition.ParameterFields("End Date").ApplyCurrentValues(pvCollection)

            '********************************* Date Range **********************************
            ' Set the discreet value to the Date Range.
            With pdvRange
                .StartValue = pdvStartName.Value
                .EndValue = pdvEndName.Value
            End With
            ' Add it to the parameter collection.
            pvCollection.Add(pdvRange)
            ' Apply the current parameter values.
            myDBRpt.DataDefinition.ParameterFields("Date Range").ApplyCurrentValues(pvCollection)
        Catch Exp As ParameterFieldException
            MsgBox("Incorrect Parameter Field. IN Parmas Procedure", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message & " in Parmas Procedure", MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub
    Public Sub CheckReportList(ByVal myReport)
        'Array for the report directories... sReportDirPath()
        '   0        1       2      3     4     5    6        
        'Acrobat\ Crystal\ Excel\ Html\ Rich\ Text\ Word\
        Dim i As Short
        Dim myExportOptions As New CrystalDecisions.Shared.ExportOptions
        Dim myDiskFileDesOptions As New CrystalDecisions.Shared.DiskFileDestinationOptions
        For i = 0 To UBound(sDirCount)
            If Not (sDirCount(i) = Nothing) Then
                Try
                    Select Case sDirCount(i)
                        Case 0   'ACROBAT
                            myDiskFileDesOptions.DiskFileName = sAppPath & sReportPath & sReportDirPath(sDirCount(i)) & "Test.pdf"
                            myExportOptions = myReport.ExportOptions
                            Dim myFormatTypeOptions As New CrystalDecisions.Shared.PdfRtfWordFormatOptions
                            With myExportOptions
                                .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                                .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
                                .DestinationOptions = myDiskFileDesOptions
                                .FormatOptions = myFormatTypeOptions
                            End With
                        Case 1    'CRYSTAL
                            myDiskFileDesOptions.DiskFileName = sAppPath & sReportPath & sReportDirPath(sDirCount(i)) & "Test.rpt"
                            myExportOptions = myReport.ExportOptions
                            Dim myFormatTypOpt As New CrystalDecisions.Shared.ReportFileFormat
                            With myExportOptions
                                .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                                .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.CrystalReport
                                .DestinationOptions = myDiskFileDesOptions
                                .FormatOptions = myFormatTypOpt
                            End With
                        Case 2    'EXCEL
                            myDiskFileDesOptions.DiskFileName = sAppPath & sReportPath & sReportDirPath(sDirCount(i)) & "Test.xls"
                            myExportOptions = myReport.ExportOptions
                            Dim myFormatTypOpt As New CrystalDecisions.Shared.ExcelFormatOptions
                            With myExportOptions
                                .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                                .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.Excel
                                .DestinationOptions = myDiskFileDesOptions
                                .FormatOptions = myFormatTypOpt
                            End With
                        Case 3    'HTML
                            myDiskFileDesOptions.DiskFileName = sAppPath & sReportPath & sReportDirPath(sDirCount(i)) & "Test.html"
                            myExportOptions = myReport.ExportOptions
                            Dim myFormatTypOpt As New CrystalDecisions.Shared.HTMLFormatOptions
                            With myExportOptions
                                .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                                .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.HTML32
                                .DestinationOptions = myDiskFileDesOptions
                                .FormatOptions = myFormatTypOpt
                            End With
                        Case 4    'RICH TEXT
                            myDiskFileDesOptions.DiskFileName = sAppPath & sReportPath & sReportDirPath(sDirCount(i)) & "Test.rtf"
                            myExportOptions = myReport.ExportOptions
                            Dim myFormatTypOpt As New CrystalDecisions.Shared.PdfRtfWordFormatOptions
                            With myExportOptions
                                .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                                .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.RichText
                                .DestinationOptions = myDiskFileDesOptions
                                .FormatOptions = myFormatTypOpt
                            End With
                        Case 5    'TEXT
                            myDiskFileDesOptions.DiskFileName = sAppPath & sReportPath & sReportDirPath(sDirCount(i)) & "Test.txt"
                            myExportOptions = myReport.ExportOptions
                            Dim myFormatTypOpt As New CrystalDecisions.Shared.MicrosoftMailDestinationOptions
                            With myExportOptions
                                .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                                .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.NoFormat
                                .DestinationOptions = myDiskFileDesOptions
                                .FormatOptions = myFormatTypOpt
                            End With
                        Case 6    'WORD
                            myDiskFileDesOptions.DiskFileName = sAppPath & sReportPath & sReportDirPath(sDirCount(i)) & "Test.doc"
                            myExportOptions = myReport.ExportOptions
                            Dim myFormatTypOpt As New CrystalDecisions.Shared.PdfRtfWordFormatOptions
                            With myExportOptions
                                .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                                .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.WordForWindows
                                .DestinationOptions = myDiskFileDesOptions
                                .FormatOptions = myFormatTypOpt
                            End With
                    End Select
                    myReport.Export()
                Catch Exp As ExportException
                    MsgBox("Incorrect path for saving report.", _
                            MsgBoxStyle.Critical, "Load Report Error")
                Catch Exp As Exception
                    MsgBox(Exp.Message & "   in CheckReportList", MsgBoxStyle.Critical, "General Error")
                End Try
            End If
        Next
    End Sub
End Class

'MODULE

Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Module modSql
    Public Const sAppPath = "C:\OLD D DIR\Visual Studio Projects\SQLproject"   '<----Add your Directory Path
    Public Const sReportPath = "Reports\"
    Public sReportDirPath() As String = {"Acrobat\", "Crystal\", "Excel\", "Html\", "Rich\", "Text\", "Word\"}
    Public Const sDBPass = "Admin"
    Public Const sDBName = "TestSQL"
    Public Const sDBServer = "MySer"
    Public Const sUSERid = "sa"
    Public Connect As SqlConnection

    '*********** Crystal Reports ****************
    Public myReport As New ReportDocument        'Gobal Report Doc
    Public sReportName As String
    Public Sub OpenDBSqlConnection()
        Try
            Connect = New SqlConnection("Initial Catalog=" & sDBName & ";Data Source=" & sDBServer & ";User ID=" & sUSERid & ";password=;")
            Connect.Open()
            Connect.Close()
        Catch Ex As Exception
            MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
        End Try

    End Sub
'THIS IS JUST EXTRA SUBS I HAD......
 
   Public Sub TableNames()
        ReDim sTables(100)
        Dim I As Integer
        Dim DS As New DataSet
        Dim sCommand As String = "SELECT table_name FROM Information_Schema.Tables"
        Dim Adapter = New SqlDataAdapter(sCommand, Connect)
        Dim sNames As String

        Adapter.Fill(DS)

        bFirstTime = True
        iCounter = 0

        For I = 0 To DS.Tables(0).Rows.Count - 1
            sNames = (DS.Tables(0).Rows(I)).Item(0)
            Select Case Left(sNames, 3)
                Case "sys"
                Case UCase(Left(sNames, 3))
                Case "tbl"
                    If bFirstTime = True Then
                        iFirstTime = I
                        bFirstTime = False
                    End If
                    sTables(I) = sNames
                    iCounter = I
            End Select
        Next

    End Sub
    Public Sub ColumunNames(ByVal sTableNames As String)
        ReDim sColumns(200)
        Dim J As Integer
        Dim sNewNames As Object

        Dim sCmd As String = "SELECT * FROM " & sTableNames
        Dim DSTableList As New DataSet
        Dim TblAdapter = New SqlDataAdapter(sCmd, Connect)

        TblAdapter.Fill(DSTableList)

        iColumnCount = DSTableList.Tables(0).Columns.Count - 1

        For J = 0 To DSTableList.Tables(0).Columns.Count - 1
            sNewNames = (DSTableList.Tables(0).Columns(J).Caption)
            sColumns(J) = sNewNames
        Next

    End Sub

End Module
0
 
LVL 1

Author Comment

by:jsctechy
Comment Utility
mlmcc:
Just as suggestion, something links are not enough you know.
I was expecting something more meaningful that read whole 593 pages of a walkthrough thing (but thanks)


planocz:
I will give it a try! Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now