我目前正在尝试使用使用 SQLCommand 执行存储过程并返回结果的类的成员来填充数据网格。
我的班级成员(以及我认为问题所在)是:
public DataView DisplayHealthIndicator(DateTime startDate, DateTime endDate)
{
string queryString =
"DECLARE @RC int"
+ "DECLARE @date_from datetime = dateadd(day, 0, datediff(day, 0, getdate()))"
+ "DECLARE @date_to datetime = dateadd(day, 0, datediff(day, 0, getdate()))"
+ "EXECUTE @RC = [Testing].[marlin].[support_retrieve_workflow_history] "
+ "@date_from "
+ ",@date_to"
+ "GO";
using (SqlConnection connection = new SqlConnection(GetConnectionString()))
{
using (var cmd = new SqlCommand(queryString, connection))
{
connection.Open();
var reader = cmd.ExecuteReader();
var dt = new DataTable();
dt.Load(reader);
return dt.DefaultView;
}
}
}
我打电话给这个成员使用:
var db = new DatabaseHandle();
dataGridWorkflow.ItemsSource = db.DisplayHealthIndicator(DateTime.Now, DateTime.Now);
然而!我目前收到错误:
Incorrect syntax near @date_from Must declare the scalar variable @RC
在一定程度上我理解错误 - 我相信我不能在我的 sqlQuery 字符串中声明变量......但是,我该怎么做呢?
我相当确定它对此没有任何影响,但如果确实如此,这是存储过程的内容:
create procedure marlin.support_retrieve_workflow_history
(
@date_from datetime,
@date_to datetime
)
as
select dateadd(day, 0, datediff(day, 0, e.event_date)) as 'Date',
c.setting_secondary 'Workflow Category' ,
d.setting_main as 'Error Type' ,
sum(e.event_count) as 'Total'
from marlin.support_events e
inner join marlin.support_config c
on e.event_category = c.setting_code
and c.config_code = 60
inner join marlin.support_config d
on e.event_type = d.setting_code
and d.config_code = 70
where e.event_date between @date_from and @date_to
group by
e.event_date,
c.setting_secondary ,
d.setting_main