• <bdo id='yTE4y'></bdo><ul id='yTE4y'></ul>

      <legend id='yTE4y'><style id='yTE4y'><dir id='yTE4y'><q id='yTE4y'></q></dir></style></legend>
    1. <tfoot id='yTE4y'></tfoot>

      <i id='yTE4y'><tr id='yTE4y'><dt id='yTE4y'><q id='yTE4y'><span id='yTE4y'><b id='yTE4y'><form id='yTE4y'><ins id='yTE4y'></ins><ul id='yTE4y'></ul><sub id='yTE4y'></sub></form><legend id='yTE4y'></legend><bdo id='yTE4y'><pre id='yTE4y'><center id='yTE4y'></center></pre></bdo></b><th id='yTE4y'></th></span></q></dt></tr></i><div id='yTE4y'><tfoot id='yTE4y'></tfoot><dl id='yTE4y'><fieldset id='yTE4y'></fieldset></dl></div>

        <small id='yTE4y'></small><noframes id='yTE4y'>

        报告在将 DataTable 设置为 DataSource 时要求数据库登录

        时间:2023-07-10

        1. <legend id='ZnQmh'><style id='ZnQmh'><dir id='ZnQmh'><q id='ZnQmh'></q></dir></style></legend>
        2. <i id='ZnQmh'><tr id='ZnQmh'><dt id='ZnQmh'><q id='ZnQmh'><span id='ZnQmh'><b id='ZnQmh'><form id='ZnQmh'><ins id='ZnQmh'></ins><ul id='ZnQmh'></ul><sub id='ZnQmh'></sub></form><legend id='ZnQmh'></legend><bdo id='ZnQmh'><pre id='ZnQmh'><center id='ZnQmh'></center></pre></bdo></b><th id='ZnQmh'></th></span></q></dt></tr></i><div id='ZnQmh'><tfoot id='ZnQmh'></tfoot><dl id='ZnQmh'><fieldset id='ZnQmh'></fieldset></dl></div>

        3. <tfoot id='ZnQmh'></tfoot>
            <bdo id='ZnQmh'></bdo><ul id='ZnQmh'></ul>
                    <tbody id='ZnQmh'></tbody>

                  <small id='ZnQmh'></small><noframes id='ZnQmh'>

                • 本文介绍了报告在将 DataTable 设置为 DataSource 时要求数据库登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  报表设计器在设计器中创建水晶报表,并通过 ODBC (DSN) 连接直接连接到数据库.相同的报告通过 DSN 的 Winform(C#) 应用程序执行,并提供数据库服务器、数据库、用户 ID 和密码.

                  Report designer creates crystal report in designer with direct connection to database with ODBC (DSN) connection. Same reports are executed via a Winform(C#) application via DSN and provides Database Server, database, user ID and password.

                  我需要对 Crystal Report 对象进行此类更改.ReportDocument 不应通过 DSN 直接连接到数据库.相反,我们将通过调用相应的存储过程和参数作为System.Data.DataTable 来通过服务带来数据.此 DataTable 对象应用于填充/生成报告.

                  I need to make such changes to the Crystal Report object. ReportDocument should not directly connect to Database via DSN. Instead, we will bring data via service by calling respective stored procedure and parameters as System.Data.DataTable. This DataTable object should be used to populate/generate reports.

                  我确实分别从 ReportDocument.DataBase.Tables[I].LocationReportDocument.DataDefinition 对象获取存储过程和参数信息.使用 ReportDocument.DataBase.Tables[I].SetDataSource(DataTable) 设置 DataSource 后,它仍然要求数据库/服务器和用户凭据连接到服务器.

                  I do get the stored procedure and parameter information from ReportDocument.DataBase.Tables[I].Location and ReportDocument.DataDefinition object respectively. After setting DataSource with ReportDocument.DataBase.Tables[I].SetDataSource(DataTable), it still ask for database/server and user credential to connect to server.

                  我们能否使用内存表而不是通过 ODBC 直接连接到数据库来实现场景并填充报告?

                  Can we achieve scenario and populate report with in-memory table instead of direct connection to database over ODBC?

                  推荐答案

                  你需要关注的两件事:

                  1. 您正在连接到用于设计报告的相同的服务器和数据库名称.
                  2. 您正在连接到一个不同的数据库或服务器.

                  场景 1:相同的服务器和数据库名称

                  在这种情况下,您需要使用 SetDatabaseLogon 方法提供凭据,如下所示

                  In this case you need to provide the credentials using SetDatabaseLogon method as follows

                  'crDoc1 is your ReportDocument
                  'dtDataTable is your DataTable
                  
                  'set database logon info
                  crDoc1.SetDatabaseLogon("db_user_name", "db_password", "db_server_name_or_ip", "database_name");
                  
                  'set DataTable as DataSource
                  crDoc1.SetDataSource(dtDataTable)
                  

                  场景 2:不同的服务器或数据库名称

                  在这种情况下,您需要使用 ApplyLogOnInfo 方法提供凭据

                  In this case you need to provide the credentials using ApplyLogOnInfo method

                  ConnectionInfo crConInfo = new ConnectionInfo();
                  TableLogOnInfo crTblLogonInfo = new TableLogOnInfo();
                  
                  crConInfo.ServerName = "db_server_name_or_ip";
                  crConInfo.DatabaseName = "database_name";
                  crConInfo.UserID = "db_user_name";
                  crConInfo.Password = "db_password";  
                  
                  'crDoc1 is your ReportDocument
                  'dtDataTable is your DataTable
                  
                  'Set DataSource to your DataTable
                  crDoc1.SetDataSource(dtDataTable)
                  
                  'after setting the DataSource apply Logon credentials to each table in ReportDocument
                  Tables CrTables = crDoc1.Database.Tables;
                  foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) {
                      crTblLogonInfo = CrTable.LogOnInfo;
                      crTblLogonInfo.ConnectionInfo = crConInfo;
                      CrTable.ApplyLogOnInfo(crTblLogonInfo);
                  }
                  crDoc1.Refresh();
                  CrystalReportViewer1.ReportSource = crDoc1;
                  

                  注意:如果您有任何子报告,您需要应用 SetDatabaseLogon 和/或 ApplyLogOnInfo 到所有子报表及其表格.

                  Notes: If you have any sub reports, you need to apply SetDatabaseLogon and/or ApplyLogOnInfo to all the sub reports and their tables respectively.

                  更新:
                  将 ApplyLogOnInfo 应用于子报表

                  UPDATE:
                  Applying ApplyLogOnInfo to subreports

                  foreach (ReportDocument srSubReport in crDoc1.Subreports) {
                      foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in srSubReport.Database.Tables) {
                          crTblLogonInfo = CrTable.LogOnInfo;
                          crTblLogonInfo.ConnectionInfo = crConInfo;
                          CrTable.ApplyLogOnInfo(crTblLogonInfo);
                      }
                  }
                  

                  这篇关于报告在将 DataTable 设置为 DataSource 时要求数据库登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在不使用数据库的情况下在运行时查看 Crystal Report 9 中的动态图像? 下一篇:什么是互操作 dll?

                  相关文章

                  <tfoot id='YevHo'></tfoot>

                    <small id='YevHo'></small><noframes id='YevHo'>

                      <bdo id='YevHo'></bdo><ul id='YevHo'></ul>
                    <i id='YevHo'><tr id='YevHo'><dt id='YevHo'><q id='YevHo'><span id='YevHo'><b id='YevHo'><form id='YevHo'><ins id='YevHo'></ins><ul id='YevHo'></ul><sub id='YevHo'></sub></form><legend id='YevHo'></legend><bdo id='YevHo'><pre id='YevHo'><center id='YevHo'></center></pre></bdo></b><th id='YevHo'></th></span></q></dt></tr></i><div id='YevHo'><tfoot id='YevHo'></tfoot><dl id='YevHo'><fieldset id='YevHo'></fieldset></dl></div>

                    1. <legend id='YevHo'><style id='YevHo'><dir id='YevHo'><q id='YevHo'></q></dir></style></legend>