Crystal Report data filling (one push mode and two PULL mode) Class Library

Source: Internet
Author: User
Crystal Report data filling (one push mode and two PULL mode) Class Library

# Region Declaration
//----------------------------------------------------------------------
//
//
// Author: Nick. Lee)
//
// Fill in the crystal report data (one push mode and two pull modes) Class Library //
//
//Boyorgril@msn.com
//
//----------------------------------------------------------------------
# Endregion

# Region data filling crystal report function set

/// <Summary>
/// Fill in crystalreport using engine. database, which is used by oledb and ODBC. In this example, It is sqlserver, Pull Mode
/// </Summary>
/// <Param name = "severname"> server name </param>
/// <Param name = "databasename"> database name </param>
/// <Param name = "userid"> User ID </param>
/// <Param name = "password"> User Password </param>
/// <Param name = "sender"> crystal report crystalreport object </param>
/* Note: when using engine. database to fill in, you must first set the relevant data fields in the Crystal Report */
Public void crydbfill (string severname, string databasename, string userid, string password, reportclass sender)
{
Tablelogoninfo crtablelogoninfo = new tablelogoninfo ();
Connectioninfo crconnectioninfo = new connectioninfo ();
Crystaldecisions. crystalreports. Engine. Database crdatabase;
Crystaldecisions. crystalreports. Engine. Tables crtables;
// Crystaldecisions. crystalreports. Engine. Table crtable;
// Object definition
Crconnectioninfo. servername = severname;
Crconnectioninfo. databasename = databasename;
Crconnectioninfo. userid = userid;
Crconnectioninfo. Password = password;
Crdatabase = sender. database;
Crtables = crdatabase. tables;
// Connect the Crystal Report to the database
Foreach (crystaldecisions. crystalreports. Engine. Table crtable in crtables)
{
Crtablelogoninfo = crtable. logoninfo;
Crtablelogoninfo. connectioninfo = crconnectioninfo;
Crtable. applylogoninfo (crtablelogoninfo );
}
// Cycle the table and fill it in
}
/// <Summary>
/// Use dataset to fill in crystalreport and reportdocument, which is dedicated to sqlserver. In push mode, different table names can be filled multiple times in a dataset.
/// </Summary>
/// <Param name = "sqltext"> database query field </param>
/// <Param name = "cnstring"> database connection field </param>
/// <Param name = "datatablename"> virtual dataset name </param>
Public void crysetfill (string sqltext, string cnstring, string datatablename)
{
// Create a data set (local variable)
System. Data. sqlclient. sqlconnection connection1 = new system. Data. sqlclient. sqlconnection (cnstring );
System. Data. sqlclient. sqldataadapter COM = new system. Data. sqlclient. sqldataadapter (sqltext, connection1 );
// Allocate memory space to Data Objects
// Allocate memory space to the data set
Com. Fill (set1, datatablename );

}
/// <Summary>
/// Implement crystalreport for setting multiple Datasets
/// </Summary>
/// <Param name = "sender"> crystal report crystalreport object </param>
Public void rptreportclassfill (reportclass sender)
{
// Data Filling
Sender. setdatasource (set1 );
// Use crysetfill first
// Print1.crydsetfill ("select * from MERs", "Server = localhost; uid = sa; Pwd = sa; database = northwind", "customers ");
// Declare the public type, for example:
// Public printclass print1 = new printclass ();
// Public crystalreport2 rep1 = new crystalreport2 ();
// Then call
// Rptreportclassfill (rep1 );
// Crystalreportviewer1.reportsource = rep1;
// Crystalreportviewer1.databind ();

// String sqltext = "select * from MERs ";
// String cnstring = "Server = localhost; uid = sa; Pwd = sa; database = northwind ;";
/* Note: To use dataset to fill in, you must first create a visual dataset. XSD, add an element to it, and display related data fields in the Crystal Report */
}

/// <Summary>
/// Implement crystalreport for setting multiple Datasets
/// </Summary>
/// <Param name = "sender"> crystal report reportdocument object </param>
Public void rptreportdocumentfill (reportdocument sender)
{
// Data Filling
Sender. setdatasource (set1 );
// Use crysetfill first
// Print1.crydsetfill ("select * from MERs", "Server = localhost; uid = sa; Pwd = sa; database = northwind", "customers ");
// Declare the public type, for example:
// Public printclass print1 = new printclass ();
// Public reportdocument rd1 = new reportdocument ();
// Then call
// Rptreportdocumentfill (rd1 );
// Crystalreportviewer1.reportsource = rd1;
// Crystalreportviewer1.databind ();

// String sqltext = "select * from MERs ";
// String cnstring = "Server = localhost; uid = sa; Pwd = sa; database = northwind ;";
/* Note: To use dataset to fill in, you must first create a visual dataset. XSD, add an element to it, and display related data fields in the Crystal Report */
}

/// <Summary>
/// Use reportdocument to fill in crystalreport, Which is oledb and ODBC. In this example, It is sqlserver and the PULL mode is used.
/// </Summary>
/// <Param name = "severname"> server name </param>
/// <Param name = "databasename"> database name </param>
/// <Param name = "userid"> User ID </param>
/// <Param name = "password"> User Password </param>
/// <Param name = "FILENAME"> obtain the name of the crystal report file in the specified path. </param>
/// <Param name = "sender"> crystal report reportdocument object </param>
Public void crydocumentfill (string severname, string databasename, string userid, string password, string filename, reportdocument sender)
{
String Path = system. Web. httpcontext. Current. server. mappath (filename );
Sender. Load (PATH );

Tablelogoninfo crtablelogoninfo = new tablelogoninfo ();

Crtablelogoninfo. connectioninfo. servername = severname;
Crtablelogoninfo. connectioninfo. Password = password;
Crtablelogoninfo. connectioninfo. databasename = databasename;
Crtablelogoninfo. connectioninfo. userid = userid;
// Set connection Parameters

// Reportdocument loading path
Sender. database. Tables [0]. applylogoninfo (crtablelogoninfo );
// Set the table connection Parameters
// Use the namespace
// Using crystaldecisions. crystalreports. engine;
// Using crystaldecisions. shared;
/* Note: when using engine. database to fill in, you must first set the relevant data fields in the Crystal Report */
// Declare the public type, for example:
// Public printclass print1 = new printclass ();
// Public reportdocument rd1 = new reportdocument ();
// Then call
// Print1.crydocumentfill ("10.141.165.136", "northwind", "sa", "sa", "MERs", "*. rpt", rd1 );
// Crystalreportviewer1.reportsource = rd1;
// Crystalreportviewer1.databind ();
}

# Endregion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.