一个在sql studio上工作的查询,但不能在c#上工作
本文关键字:工作 但不能 查询 studio 一个 sql | 更新日期: 2023-09-27 18:05:27
我有这个查询,当我在Sql studio上执行它时,我得到结果:
select TeamName, count(*)
from NetHoz_Decision
inner join NetHoz_Case on NetHoz_Decision.CaseDisplayIdentifier = NetHoz_Case.CaseDisplayIdentifier
inner join maintik on MainTik.Counter = NetHoz_Case.TikCounter
inner join Teams on MainTik.TeamCounter = Teams.Counter
where NetHoz_Decision.DecisionStatusChangeDate between '2015-07-23' and '2015-07-28'
group by TeamName
但是当我在c# SqlCommand上执行时,我没有得到任何结果。数据集是空的,我没有得到任何错误。我以为问题出在约会上。我转换对了吗?
String date1 = String.Format("{0:yyyy-MM-dd}", dateTimePicker1.Value);
String date2 = String.Format("{0:yyyy-MM-dd}", dateTimePicker2.Value.AddDays(1));
使用SqlCommand和类型安全参数
const string query = "
select TeamName, count(*)
from NetHoz_Decision
inner join NetHoz_Case on NetHoz_Decision.CaseDisplayIdentifier = NetHoz_Case.CaseDisplayIdentifier
inner join maintik on MainTik.Counter = NetHoz_Case.TikCounter
inner join Teams on MainTik.TeamCounter = Teams.Counter
where NetHoz_Decision.DecisionStatusChangeDate between @from and @to
group by TeamName
";
SqlCommand command = new SqlCommand(query);
command.Parameters.AddWithValue("@from", dateTimePicker1.Value);
command.Parameters.AddWithValue("@to", dateTimePicker2.Value.AddDays(1));