Click here to Skip to main content
15,895,606 members
Articles / Desktop Programming / Windows Forms

Crystal Report Filtering Using Selection Parameters

Rate me:
Please Sign up or sign in to vote.
4.88/5 (15 votes)
2 Jun 2011CPOL3 min read 264K   9.2K   28  
Beginner's Guide to Crystal Report Filtering
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace CrytsalReportsDemo
{
    public partial class frmReportViewer : Form
    {
        ReportDocument m_cryRpt;
        public frmReportViewer(ReportDocument cryRpt)
        {
            InitializeComponent();
            m_cryRpt = cryRpt;
        }

        private void frmReportViewer_Load(object sender, EventArgs e)
        {
            DbConnectionInfo.SetConnectionString(ConfigurationSettings.AppSettings[0]);
            TableLogOnInfo logOnInfo;
            ConnectionInfo connectionInfo;
            foreach (Table table in m_cryRpt.Database.Tables)
            {
                logOnInfo = table.LogOnInfo;
                connectionInfo = logOnInfo.ConnectionInfo;
                // Set the Connection parameters.
                connectionInfo.DatabaseName = DbConnectionInfo.InitialCatalog;
                connectionInfo.ServerName = DbConnectionInfo.ServerName;
                if (!DbConnectionInfo.UseIntegratedSecurity)
                {
                    connectionInfo.Password = DbConnectionInfo.Password;
                    connectionInfo.UserID = DbConnectionInfo.UserName;
                }
                else
                {
                    connectionInfo.IntegratedSecurity = true;
                }
                table.ApplyLogOnInfo(logOnInfo);
            }

            crystalReportViewer1.ReportSource = m_cryRpt;
            crystalReportViewer1.Refresh();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer
Egypt Egypt
Enthusiastic programmer/researcher, passionate to learn new technologies, interested in problem solving, data structures, algorithms, AI, machine learning and nlp.

Amateur guitarist/ keyboardist, squash player.

Comments and Discussions