Visual Studio与Access 2007中的Crystal报表 [英] Crystal Report in Visual Studio with Access 2007

查看:116
本文介绍了Visual Studio与Access 2007中的Crystal报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用ODBC或OLEDB驱动程序在Visual Studio 2008中使用Access 2007数据库设计报表。但是,当我尝试打印它(运行代码后),我得到无效的登录参数错误,而它与Access 2003数据库运行良好。以下是我的代码:



I am able to design a report in Visual Studio 2008 with Access 2007 Database by using the ODBC or OLEDB driver. But when I try to print it (after running the code), I get the invalid logon parameters Error while it worked well with Access 2003 database. Below is my code:

creport_laundry crReportDocument = new creport_laundry();
            Database crDatabase;
            Tables crTables;
            Table crTable;
            TableLogOnInfo crTableLogOnInfo;
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
 
            crConnectionInfo.ServerName = @"d:\db2.accdb";
            crConnectionInfo.DatabaseName = @"d:\db2.accdb";
 
            crConnectionInfo.Password = "xyz"
            crDatabase = crReportDocument.Database;
            crTables = crDatabase.Tables;
            for (int i = 0; i < crTables.Count; i++)
            {
                crTable = crTables[i];
                crTableLogOnInfo = crTable.LogOnInfo;
                crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                crTable.ApplyLogOnInfo(crTableLogOnInfo);
            }
crReportDocument.PrintToPrinter(1, false, 0, 0);





我花的钱多于10个小时没有解决方案。任何帮助都将非常感激。



I have spent more than 10 hours on this without a solution. Any help would be HIGHLY appreciated.

推荐答案

我已经检查了你的代码&发现了一些问题。



你必须传递这4个参数的值,如下所示

I have checked your code & found some issues.

You must pass values for those 4 parameters like as below
crConnectionInfo.ServerName = "MachineName";//It should be machine name
crConnectionInfo.DatabaseName = @"d:\db2.accdb";
crConnectionInfo.UserID = "Administrator";//You forgot to give value for this
crConnectionInfo.Password = "xyz"





进一步阅读

C#Crystal Reports动态登录参数 [ ^ ]


首先,连接到Access数据库时的服务器名称包含完整路径和它在Access 2003中运行良好

其次,Access 2003数据库中不需要用户ID和密码

最后,我仍然按照您的解决方案但没有结果。请帮助:(
First, Server Name when connecting to Access Database contains the complete path and it worked well with Access 2003
Second, Even User Id and Password werent required in Access 2003 Database
Lastly, I still followed your solution but with no results. Please Help :(


我希望这个帮助: -



i hope this help :-

DataSet ds = new DataSet();
            
            creport_laundry crReportDocument  = new creport_laundry();
            ReportDocument rptFile = new ReportDocument();
            ds = clsHlpr.ExecuteDataset(connection_name, CommandType.Text, "select * from abc");
            if (ds.Tables[0].Rows.Count > 0)
            {
                rptform.Text = ".........";
                rptFile.Load(Application.StartupPath + "\\mainR.rpt");
                
                crReportDocument.crys.ReportSource = rptFile;
                rptFile.SetDatabaseLogon("admin", "lbbs");
                rptFile.SetDataSource(ds);
                crReportDocument.crys.RefreshReport();
                rptFile.Refresh();
                rptFile.PrintToPrinter(1, false, 0, 0);// for send repot direct to print
                      //or
                crReportDocument.crys.Show();//for show report
                crReportDocument.Show();

                            }


这篇关于Visual Studio与Access 2007中的Crystal报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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