我目前正在尝试在我的SQL Server数据库中使用Datetime
类型的参数执行Select
。但我需要这个参数只因为在SQL下面的查询我使用的格式YYYY-MM-DD
日期和它的工作:C#在SQL Server中选择仅使用带有SQL参数的日期
select
idCliente, DescCliente, DescAnalista , StatusChamado , DataAtendimento
from
Atendimento
where
cast ([DataAtendimento] as date) = '2016-04-27';
我看了几个帖子,表明我使用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';";
我需要你们的帮助,我没有找到一个可以执行此选择
删除'='@adate';'中的''''。 –
我不能相信我因为这些引用而被捕了几个小时,它工作得很好,谢谢 –
我们都去过那里。 =) –