簡體   English   中英

使用c#和ms-access和數據集時的Crystal Report數據庫登錄提示

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

我正在使用Crystal Report並將數據集綁定到我的Windowsform應用程序中。 我的數據集正在從ms-access數據庫中獲取數據,並且查詢工作很酷。 我沒有為我的數據庫或數據集或其他任何東西設置任何登錄信息,但仍在報告加載時要求登錄。 在登錄頁面中,服務器名稱是我的數據集的名稱,所有其他字段均為空。 ms-access 2016-visual-studio 2015-水晶報表13.0.14

我的代碼

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

我的查詢

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

我已經有一段時間沒有處理Crystal報表了,但是我很確定您必須單擊WinForm中的Crystal Report Viewer對象,並將該屬性更改為無需登錄。 此外,在引用文件路徑時,請使用以下約定:cryRpt.Load(@“ C:\\ directory \\ word.txt”(@“ D:\\ c#\\ AttendanceApp \\ AttendanceApp \\ CrystalReport_Work.rpt”)。

嘗試下面的示例,請確保設置您的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