C # crystal report printing bound database table

Source: Internet
Author: User

Reference some code. I didn't think so much about it. I just kept it for reference. I don't need to take this document back and forth in the future.

Public String username = string. empty;
Public String number = string. empty;
/// <Summary>
/// Crystal Report 1
/// </Summary>
Private void initrept ()
{
Try
{
Datatable dt = new datatable ("pzhtable ");
DT. Columns. Add ("name ");
DT. Columns. Add ("Number ");
DT. Columns. Add ("name1 ");
DT. Columns. Add ("number1 ");

Datarow newrow = DT. newrow ();
Newrow ["name"] = username;
Newrow ["Number"] = number;
Newrow ["name1"] = username;
Newrow ["number1"] = number;
DT. Rows. Add (newrow );
ReportDocument RPTC = new reportdocument ();
String rptfile = application. startuppath + "\ Rept. rpt ";
RPTC. Load (rptfile );
RPTC. database. Tables [0]. setdatasource (DT );
This. crystalreportviewer1.reportsource = RPTC;
Crystalreportviewer1.printreport ();
}
Catch (exception ex)
{
MessageBox. Show (ex. tostring ());
}
}

// Call and pass the value

Rept. frmrept FRM = new Rept. frmrept ();
FRM. Username = username;
FRM. Number = convert. toint32 (lblnumber. Text. Trim (). tostring ();
FRM. showdialog ();

/// <Summary>
/// Crystal Report 2
/// </Summary>
Private void initrept ()
{
Try
{
Datatable dt = new datatable ("zigetable ");
DT. Columns. Add ("name ");
DT. Columns. Add ("zigehao ");
DT. Columns. Add ("name1 ");
DT. Columns. Add ("zigehao1 ");
DT. Columns. Add ("name2 ");
DT. Columns. Add ("zigehao2 ");
String MySQL = "select * From zigetable order by shunxuhao ASC ";
Datatable newdt = new dataaccess (). getdataset (MySQL). Tables [0];
If (newdt! = NULL & newdt. Rows. Count> 0)
{
For (INT I = 0; I <newdt. Rows. Count; I ++)
{
Datarow newrow = DT. newrow ();
If (I <newdt. Rows. Count-1)
{
Newrow ["name"] = newdt. Rows [I] ["clientinfoid"]. tostring ();
Newrow ["zigehao"] = newdt. Rows [I] ["shunxuhao"]. tostring ();
}
If (I <newdt. Rows. Count-1)
{
Newrow ["name1"] = newdt. Rows [I + 1] ["clientinfoid"]. tostring ();
Newrow ["zigehao1"] = newdt. Rows [I + 1] ["shunxuhao"]. tostring ();
}
If (I <newdt. Rows. Count-2)
{
Newrow ["name2"] = newdt. Rows [I + 2] ["clientinfoid"]. tostring ();
Newrow ["zigehao2"] = newdt. Rows [I + 2] ["shunxuhao"]. tostring ();
}
I = I + 2;
DT. Rows. Add (newrow );
}

ReportDocument RPTC = new reportdocument ();
String rptfile = application. startuppath + "\ reptxh. rpt ";
RPTC. Load (rptfile );
RPTC. database. Tables [0]. setdatasource (DT );
This. crystalreportviewer1.reportsource = RPTC;

}
}
Catch (exception ex)
{
MessageBox. Show (ex. tostring ());
}
}

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.