水晶报表sql server和access登录区别问题,送分啊

professorzhou 2005-09-22 01:05:40
报表连接sql server(新建时候连接用oledb)老是出现登录数据库服务器提示框,无法登录,但是access就没有问题,代码如下:
CrystalReport3 oRpt=new CrystalReport3();
TableLogOnInfo logOnInfo = new TableLogOnInfo ();
int i = 0;
// 对报表中的每个表依次循环。
for (i=0;i == oRpt.Database.Tables.Count - 1;i++)
{
// 设置当前表的连接信息。

logOnInfo.ConnectionInfo.ServerName = "localhost";
logOnInfo.ConnectionInfo.DatabaseName = "a";
logOnInfo.ConnectionInfo.UserID = "sa";
logOnInfo.ConnectionInfo.Password = "";
oRpt.Database.Tables[0].ApplyLogOnInfo(logOnInfo);
}

//建立.rpt文件与CryStalReportviewer文件之间的连接
CrystalReportViewer1.ReportSource = oRpt;
CrystalReportViewer1.DataBind();
上面代码中,我连接sql server数据库就会出现无法登录页面,提示登录数据库的文本框,但填了还是没用。但是我用access数据库的话就能够成功,为什么啊?
请大侠帮帮我,很急啊!!
...全文
259 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaojingzfj 2005-12-12
  • 打赏
  • 举报
回复
没有声明ReportDocument对象

应这样
ReportDocument myDoc=new ReportDocument();

TableLogOnInfo logOnInfo = new TableLogOnInfo();
for(int i=0;i<myDoc.Database.Tables.Count;i++)
{
logOnInfo.ConnectionInfo.ServerName = "服务器名";
logOnInfo.ConnectionInfo.DatabaseName = "数据库名";
logOnInfo.ConnectionInfo.UserID = "用户名";
logOnInfo.ConnectionInfo.Password = "密码";
myDoc.Database.Tables[i].ApplyLogOnInfo(logOnInfo);
}

crystalReportViewer1.ReportSource =myDoc;
add8849 2005-12-02
  • 打赏
  • 举报
回复
友情up
flyskylf 2005-11-26
  • 打赏
  • 举报
回复
我也需要知道,
flyskylf 2005-11-26
  • 打赏
  • 举报
回复
顶!!!!!
lyb_abiandbel 2005-09-22
  • 打赏
  • 举报
回复
你最好还是用sql连接,因为oledb和sql的连接信息不是一样的.

如果你用的是水晶报表的推模式,一般不用设置登陆信息,但是要这样写:obj.SetDataSource(this.ds.Tables["tablename"]);如果你写成了obj.SetDataSource(this.ds)就会有登陆框的。

如果你用的是水晶报表的拉模式,你就一定要写上登陆信息:

crReportDocument = new OracleReport();

//Set the crConnectionInfo with the current values stored in the report
crConnectionInfo = crReportDocument.Database.Tables[0].LogOnInfo.ConnectionInfo;

/* Populate the ConnectionInfo Objects Properties with the appropriate values for
the ServerName, User ID, Password and DatabaseName. However, since Oracle
works on Schemas, Crystal Reports does not recognize or store a DatabaseName.
Therefore, the DatabaseName property must be set to a BLANK string. */
crConnectionInfo.DatabaseName = "";
crConnectionInfo.ServerName = "Your Server Name";
crConnectionInfo.UserID = "Your User ID";
crConnectionInfo.Password = "Your Password";

//Set the CrDatabase Object to the Report's Database
crDatabase = crReportDocument.Database;

//Set the CrTables object to the Tables collection of the Report's dDtabase
crTables = crDatabase.Tables;

//Loop through each Table object in the Tables collection and apply the logon info
//specified ealier. Note this sample only has one table so the loop will only execute once
foreach (Table crTable in crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo (crTableLogOnInfo);

// if you wish to change the schema name as well, you will need to set Location property as follows:
// crTable.Location = "<new schema name>." + crTable.Name;
}

//Set the ReportSource of the CrystalReportViewer to the strongly typed Report included in the project
crystalReportViewer1.ReportSource = crReportDocument;

还有一点要注意:
如果你用到了子报表,一定要处理:

//Go through each sections in the main report and identify the subreport by name
crSections = crReportDocument.ReportDefinition.Sections;

foreach(Section crSection in crSections)
{
crReportObjects = crSection.ReportObjects;
//loop through all the report objects to find all the subreports
foreach(ReportObject crReportObject in crReportObjects)
{
if (crReportObject.Kind == ReportObjectKind.SubreportObject)
{
//you will need to typecast the reportobject to a subreport
//object once you find it
crSubreportObject = (SubreportObject)crReportObject;

//open the subreport object
crSubReportDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
//Once the correct subreport has been located pass it the
//appropriate dataset
if(crSubReportDoc.Name == "FirstSub")
{
//crSubReportDoc.Database.Tables[0].SetDataSource(ds);
crSubReportDoc.SetDataSource(ds);
}
}
}
}
crystalReportViewer1.ReportSource = crReportDocument;

同样crSubReportDoc.SetDataSource(ds);改为:crSubReportDoc.SetDataSource(ds.Tables["tablename"]);

http://dev.csdn.net/develop/article/76/76324.shtm

4,818

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧