如何以编程方式C#在Crystal报表中连接sybase数据库 [英] How to connect the sybase database in Crystal report Programmatically C#

查看:100
本文介绍了如何以编程方式C#在Crystal报表中连接sybase数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个报告并通过报告向导连接到数据库,我的报告打开并在设计中显示数据,但是当我运行我的应用程序和路径时,一个参数报告错误



我的代码

 私人  void  logInfo()
{
ReportDocument crystalReport = new ReportDocument();
// ODBC; Driver = Sybase SQL Anywhere 8.0; Uid = dbo; Pwd = dbo; Dsn = DC;
crystalReport.Load(Application.StartupPath + \\ + v_agl_ledg.rpt< /跨度>);

// 设置数据库登录信息
// crystalReport.SetDatabaseLogon(dbo,dbo,ODBC; Driver = Sybase SQL Anywhere 8.0;,DC, true);

// 提供参数值
crystalReport.SetParameterValue( datFrom,Dat_from.Value); // CB_PurOrdSrl.SelectedValue.ToString()
crystalReport.SetParameterValue( datTo,Dat_To.Value);

crystalReportViewer1.ReportSource = crystalReport;
crystalReportViewer1.Visible = true ;
}

解决方案

试试这个...

 public ReportDocument _objReportDocument = new ReportDocument(); 
_objReportDocument.Load(rptPath);
_objReportDocument.SetDatabaseLogon(DB_UID,Utilities.DB_PWD,DB_SERVER_NAME,DB_NAME));
_objReportDocument.SetParameterValue(paramName,paramVal); //如果需要
RptViewer.ReportSource = _objReportDocument; // RptViewer是CrystalReportViewer控件


< blockquote>我的错误是登录失败我的数据库在ODBC DataBase上类型Sql AnyWhere8但是当我创建我的报告他连接数据库是成功

我的问题

当我运行程序show时我对DataBase的屏幕联系我已经在联系代码中写了句子和用户名和密码我需要知道我的代码中的错误

Plz帮助

我的代码

 ReportDocument crystalReport =  new  ReportDocument(); 
// ODBC; Driver = Sybase SQL Anywhere 8.0; Uid = dbo; Pwd = dbo; Dsn = DC;
crystalReport.Load(Application.StartupPath + \\ + v_agl_assistant_ledger_a.rpt< /跨度>);

// 设置数据库登录信息

crystalReport.SetDatabaseLogon( dbo dbo ODBC;驱动程序= Sybase SQL Anywhere 8.0 DC true );

// 提供参数值
crystalReport.SetParameterValue(< span class =code-string>
datFrom,Dat_from.Value); // CB_PurOrdSrl.SelectedValue.ToString()
crystalReport.SetParameterValue( datTo,Dat_To.Value);

crystalReportViewer1.ReportSource = crystalReport;
crystalReportViewer1.Visible = true ;


i create a report and connect to data base by report wizard and my report open and display data in design but when i run my app and path a param to report error

my code

private void logInfo()
    {
        ReportDocument crystalReport = new ReportDocument();
        //ODBC; Driver=Sybase SQL Anywhere 8.0;Uid=dbo;Pwd=dbo;Dsn=DC;
        crystalReport.Load(Application.StartupPath + "\\" + "v_agl_ledg.rpt");

        //Set DataBase Login Info
        //crystalReport.SetDatabaseLogon("dbo", "dbo", "ODBC; Driver=Sybase SQL Anywhere 8.0;", "DC", true);

        //Provide parameter values
        crystalReport.SetParameterValue("datFrom", Dat_from.Value);//CB_PurOrdSrl.SelectedValue.ToString()
        crystalReport.SetParameterValue("datTo", Dat_To.Value);

        crystalReportViewer1.ReportSource = crystalReport;
        crystalReportViewer1.Visible = true;
    }

解决方案

Try this ...

public ReportDocument _objReportDocument= new ReportDocument();
_objReportDocument.Load(rptPath);
_objReportDocument.SetDatabaseLogon(DB_UID,Utilities.DB_PWD,DB_SERVER_NAME,DB_NAME));
_objReportDocument.SetParameterValue(paramName, paramVal);//If needed
RptViewer.ReportSource = _objReportDocument;//RptViewer is the CrystalReportViewer control


my error is Logon failed my database on ODBC DataBase Type Sql AnyWhere8 but when i create my report he connect database is Successfully
My problem
When I run the program show me screen contact for the DataBaseand I am already in contact code written sentences and username and password i need Know Where The error in my code
Plz Help
my Code

ReportDocument crystalReport = new ReportDocument();
            //ODBC; Driver=Sybase SQL Anywhere 8.0;Uid=dbo;Pwd=dbo;Dsn=DC;
            crystalReport.Load(Application.StartupPath + "\\" + "v_agl_assistant_ledger_a.rpt");
 
            //Set DataBase Login Info
            
             crystalReport.SetDatabaseLogon("dbo", "dbo", "ODBC; Driver=Sybase SQL Anywhere 8.0", "DC", true);

             //Provide parameter values
              crystalReport.SetParameterValue("datFrom", Dat_from.Value);//CB_PurOrdSrl.SelectedValue.ToString()
              crystalReport.SetParameterValue("datTo", Dat_To.Value);
 
              crystalReportViewer1.ReportSource = crystalReport;
              crystalReportViewer1.Visible = true;


这篇关于如何以编程方式C#在Crystal报表中连接sybase数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆