If the SQL database has a password, the dialog box will pop up.

Source: Internet
Author: User
Hello, if the SQL database has a password, the dialog box will pop up. You can use the code to dynamically set the data source for the crystal report and use the following code to try it.
// Bind report data
Private void bindcrystalreports ()
{
String path1 = server. mappath ("~ \ Report \\");
String path2 = path1 + "reporder. rpt ";
ReportDocument repdoc = new reportdocument ();
Repdoc. Load (path2 );
Setdblogonforreport (repdoc); // set the data logon information
Crorder. reportsource = repdoc;
String selectionformula = "{htorder. htid} =" + txthtid. Text. Trim (); // sets the report data filtering formula.
Repdoc. datadefinition. recordselectionformula = selectformula;
Crorder. databind ();
}
// Set logon information
Private void setdblogonforreport (reportdocument)
{
Try
{
Connectioninfo = new connectioninfo ();
ConnectionInfo. ServerName = ConfigurationManager. etettings ["ServerName"];
ConnectionInfo. DatabaseName = ConfigurationManager. etettings ["DatabaseName"];
ConnectionInfo. UserID = ConfigurationManager. etettings ["UserID"];
ConnectionInfo. Password = ConfigurationManager. etettings ["Password"];
Tables tables = reportDocument. Database. Tables;
Foreach (CrystalDecisions. CrystalReports. Engine. Table table in tables)
{
TableLogOnInfo tableLogonInfo = table. LogOnInfo;
TableLogonInfo. ConnectionInfo = connectionInfo;
Table. ApplyLogOnInfo (tableLogonInfo );
}
}
Catch
{
LblNote. Text = "<script> alert ('the database logon information is incorrect! '); </Script> ";
}
}

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.