简体   繁体   中英

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. my dataset is getting data from a ms-access database and it queries are working cool. 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

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. 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").

Try the below example, be sure to set your 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;
            }
        }
    }
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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