我正在尝试将新的 DateTime 2013-09-22 传递到以下内容,但是它表明我的 sql 语法中有错误。任何想法?
DateTime WeekEnding = new DateTime(2013, 9, 22);
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand(
@"select WeekEnding, sum(Total) as Total " +
"from Data where WeekEnding = '@WeekEnding' " +
"group by WeekEnding",
myConnection);
myCommand.Parameters.Add("@WeekEnding", SqlDbType.DateTime);
myCommand.Parameters["@WeekEnding"].Value = WeekEnding;
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
Console.WriteLine("Combined : " + myReader["Total"].ToString());
}