相信大家都见过下面的代码了,可是我在使用的时候却报错:
一、导入水晶报表使用的动态联接库:根据实际修改文件路径。 #import "C:\Documents and Settings\Administrator\桌面\cr\craxdrt9.dll" no_namespace二、定义接口指针变量 //水晶报表变量
IApplicationPtr m_Application;
IReportPtr m_Report;
//水晶报表控件变量,在对话框中加入该控件
CCrystalReportViewer9 m_CRViewer1;三、具体实现步骤 //实例化m_Application
m_Application.CreateInstance (__uuidof(Application));
//获取m_Report变量
//staff.rpt为通过向导建立的报表文件,数据库采用SQL Server 7.0
m_Report =m_Application->OpenReport ("C:\\Documents and Settings\\Administrator\\桌面\\cr\\debug\\staff.rpt");
//设置报表标题
m_Report->put_ReportTitle (_bstr_t("Title"));
//设置数据库连接变量
//数据库服务器(local),数据库名staff,用户名sa,密码sa
m_Report->Database ->Tables ->Item [1]->SetLogOnInfo("(local)","staff","sa","sa");
//设置检索SQL命令
m_Report->put_SQLQueryString ((_bstr_t)"select * from person where id<'4' order by id");
//不显示重复字段
m_Report->PutEnableSelectDistinctRecords (TRUE);
//设置检索条件,采用水晶报表语法,功能同设置检索SQL命令
m_Report->PutRecordSelectionFormula ((_bstr_t)"{person.id}='1'");
//设置报表作者
m_Report->PutReportAuthor ("xiaojin");
//将m_Report与报表控件连接
m_CRViewer1.SetReportSource(m_Report);
//显示报表工具条
m_CRViewer1.SetDisplayToolbar (TRUE);
//不显示报表左边的分组树
m_CRViewer1.SetDisplayGroupTree (FALSE);
//不显示控件边框
m_CRViewer1.SetDisplayBorder (FALSE);
//刷新数据
m_CRViewer1.Refresh ();
//显示报表内容
m_CRViewer1.ViewReport();这样,漂亮的水晶报表就显示出来了。程序异常处理部分省略,请自行加入。 当程序执行到:
//设置数据库连接变量
//数据库服务器(local),数据库名staff,用户名sa,密码sa
m_Report->Database ->Tables ->Item [1]->SetLogOnInfo("(local)","staff","sa","sa");
的时候就报错,怎么回事呢?我用的是MS SQL server 2000,数据库服务器、数据库名字等都没有错误啊。
一、导入水晶报表使用的动态联接库:根据实际修改文件路径。 #import "C:\Documents and Settings\Administrator\桌面\cr\craxdrt9.dll" no_namespace二、定义接口指针变量 //水晶报表变量
IApplicationPtr m_Application;
IReportPtr m_Report;
//水晶报表控件变量,在对话框中加入该控件
CCrystalReportViewer9 m_CRViewer1;三、具体实现步骤 //实例化m_Application
m_Application.CreateInstance (__uuidof(Application));
//获取m_Report变量
//staff.rpt为通过向导建立的报表文件,数据库采用SQL Server 7.0
m_Report =m_Application->OpenReport ("C:\\Documents and Settings\\Administrator\\桌面\\cr\\debug\\staff.rpt");
//设置报表标题
m_Report->put_ReportTitle (_bstr_t("Title"));
//设置数据库连接变量
//数据库服务器(local),数据库名staff,用户名sa,密码sa
m_Report->Database ->Tables ->Item [1]->SetLogOnInfo("(local)","staff","sa","sa");
//设置检索SQL命令
m_Report->put_SQLQueryString ((_bstr_t)"select * from person where id<'4' order by id");
//不显示重复字段
m_Report->PutEnableSelectDistinctRecords (TRUE);
//设置检索条件,采用水晶报表语法,功能同设置检索SQL命令
m_Report->PutRecordSelectionFormula ((_bstr_t)"{person.id}='1'");
//设置报表作者
m_Report->PutReportAuthor ("xiaojin");
//将m_Report与报表控件连接
m_CRViewer1.SetReportSource(m_Report);
//显示报表工具条
m_CRViewer1.SetDisplayToolbar (TRUE);
//不显示报表左边的分组树
m_CRViewer1.SetDisplayGroupTree (FALSE);
//不显示控件边框
m_CRViewer1.SetDisplayBorder (FALSE);
//刷新数据
m_CRViewer1.Refresh ();
//显示报表内容
m_CRViewer1.ViewReport();这样,漂亮的水晶报表就显示出来了。程序异常处理部分省略,请自行加入。 当程序执行到:
//设置数据库连接变量
//数据库服务器(local),数据库名staff,用户名sa,密码sa
m_Report->Database ->Tables ->Item [1]->SetLogOnInfo("(local)","staff","sa","sa");
的时候就报错,怎么回事呢?我用的是MS SQL server 2000,数据库服务器、数据库名字等都没有错误啊。
有什么更好的方法吗?您是怎么使用的?谢谢!
还是不行啊,这几个参数到底怎么设置阿