我创建了两种方法,允许使用高级搜索来显示Logs表:
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。但是,当我触发第二种方法时,只更新了参数字段值。报告的细节仍然相同。
我错过了什么吗?
答案 0 :(得分:1)
report.SetDatabaseLogon("username", "password", "(local)", "database");
report.SetDataSource(ds);
除了要推送的数据集外,您的报告是否还有单独的数据库连接?
答案 1 :(得分:0)
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);
cmd.Parameters["@Start"].Value = dtpStart.Value.Date;
cmd.Parameters.Add("@End", SqlDbType.DateTime);
cmd.Parameters["@End"].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();
问题仍然是第二种方法是否实际被触发。如果是,则错误发生在SQL语句中,否则,则触发器错误。