我创建了两种允许使用高级搜索来显示日志表的方法:
void GetLogs()
{
DateTime start = GetFirstRecord();
DateTime end = GetLastRecord();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Logs.LogID, Users.LastName, Users.FirstName, " +
"Logs.LogType, Logs.Description, Logs.Timestamp FROM Logs INNER JOIN Users " +
"ON Logs.UserID = Users.UserID";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Report");
rptLogs report = new rptLogs();
report.SetDatabaseLogon("username", "password", "(local)", "database");
report.SetDataSource(ds);
report.SetParameterValue("Start", start);
report.SetParameterValue("End", end);
crvLogs.ReportSource = report;
crvLogs.Refresh();
con.Close();
}
和
void GetLogsByTimestamp()
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Logs.LogID, Users.LastName, Users.FirstName, " +
"Logs.LogType, Logs.Description, Logs.Timestamp FROM Logs INNER JOIN Users " +
"ON Logs.UserID = Users.UserID WHERE Logs.Timestamp BETWEEN @Start AND @End";
cmd.Parameters.Add("@Start", SqlDbType.DateTime).Value = dtpStart.Value.Date;
cmd.Parameters.Add("@End", SqlDbType.DateTime).Value = dtpEnd.Value.Date;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Report");
rptLogs report = new rptLogs();
report.SetDatabaseLogon("username", "password", "(local)", "database");
report.SetDataSource(ds);
report.SetParameterValue("Start", dtpStart.Value.Date);
report.SetParameterValue("End", dtpEnd.Value.Date);
crvLogs.ReportSource = report;
crvLogs.Refresh();
con.Close();
}
第一种方法在应用程序中正确加载了 Crystal Report。但是,当我触发第二种方法时,只有参数字段值被更新。报告的细节仍然相同。
我错过了什么吗?