简体   繁体   English

使用c#和ms-access和数据集时的Crystal Report数据库登录提示

[英]crystal report database login prompt when using c# and ms-access and dataset

i'm using crystal report and bind a dataset to it in my windowsform application. 我正在使用Crystal Report并将数据集绑定到我的Windowsform应用程序中。 my dataset is getting data from a ms-access database and it queries are working cool. 我的数据集正在从ms-access数据库中获取数据,并且查询工作很酷。 i did not set any login info for my database or dataset or any thing else and still when the report is loading it ask for login. 我没有为我的数据库或数据集或其他任何东西设置任何登录信息,但仍在报告加载时要求登录。 in login page the server name is the name of my dataset and all other field are empty. 在登录页面中,服务器名称是我的数据集的名称,所有其他字段均为空。 ms-access 2016 - visual-studio 2015 - crystal report 13.0.14 ms-access 2016-visual-studio 2015-水晶报表13.0.14

my code 我的代码

ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load("D:/c#/AttendanceApp/AttendanceApp\\CrystalReport_Work.rpt");
            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();

my query 我的查询

SELECT        p.Personal_FingerId, p.Personal_Name, p.Personal_Family, w.Work_Date, Format(MIN(CDate(w.Work_Time)), 'hh:nn') AS Time_Start, Format(MAX(CDate(w.Work_Time)), 'hh:nn') AS Time_Finish
FROM            (Table_Personal p INNER JOIN
                         Table_WorkUser w ON p.Personal_FingerId = w.Personal_FingerId)
GROUP BY p.Personal_Name, p.Personal_Family, p.Personal_FingerId, w.Work_Date
ORDER BY w.Work_Date

I haven't handle crystal report in a while but I'm pretty sure you have to click on the Crystal Report Viewer object in your WinForm and change the property to no login required. 我已经有一段时间没有处理Crystal报表了,但是我很确定您必须单击WinForm中的Crystal Report Viewer对象,并将该属性更改为无需登录。 In addition, when referring to a file path use this convention: @"C:\\directory\\word.txt" for your cryRpt.Load(@"D:\\c#\\AttendanceApp\\AttendanceApp\\CrystalReport_Work.rpt"). 此外,在引用文件路径时,请使用以下约定:cryRpt.Load(@“ C:\\ directory \\ word.txt”(@“ D:\\ c#\\ AttendanceApp \\ AttendanceApp \\ CrystalReport_Work.rpt”)。

Try the below example, be sure to set your DataSource. 尝试下面的示例,请确保设置您的DataSource。

private void Form1_Load(object sender, EventArgs e)
{
CustomerReport crystalReport = new CustomerReport();
Customers dsCustomers = GetData();
crystalReport.SetDataSource(dsCustomers);
this.crystalReportViewer1.ReportSource = crystalReport;
this.crystalReportViewer1.RefreshReport();
}

private Customers GetData()
{
string constr = @"Data Source=.\Sql2005;Initial Catalog=Northwind;Integrated Security = true";
using (SqlConnection con = new SqlConnection(constr))
{
    using (SqlCommand cmd = new SqlCommand("SELECT TOP 20 * FROM Customers"))
    {
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;
            sda.SelectCommand = cmd;
            using (Customers dsCustomers = new Customers())
            {
                sda.Fill(dsCustomers, "DataTable1");
                return dsCustomers;
            }
        }
    }
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM