我目前正在尝试Select使用带有Datetime类型的参数在我的SQL Server数据库中执行.但我需要此参数只有格式YYYY-MM-DD日期,因为我正在使用的SQL中的以下查询,它正在工作:
select
idCliente, DescCliente, DescAnalista , StatusChamado , DataAtendimento
from
Atendimento
where
cast ([DataAtendimento] as date) = '2016-04-27';
Run Code Online (Sandbox Code Playgroud)
我阅读了几个帖子,表明我使用DbType或者.ToString在运行时发生错误,指出无法将字符串转换为日期/时间格式.
这是我如何使用SqlParameter:
DateTime date;
date = Data;
try
{
sqlClient.Command.Parameters.AddWithValue("@adate", date);
sqlClient.Command.CommandText = @" select idCliente, DescCliente, DescAnalista , StatusChamado , DataAtendimento from Atendimento where cast ([DataAtendimento] as date) = '@adate';";
Run Code Online (Sandbox Code Playgroud)
我需要你们的帮助,我找不到任何可以执行此选择的方法