将数据类型nvarchar转换为日期时出错。 [英] Error converting data type nvarchar to date.
本文介绍了将数据类型nvarchar转换为日期时出错。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了Google并尝试解决此错误但没有用。错误仍然存在。
当试图执行此行时
I tried Google and trying to solve this error but of no use. the error still persists.
When tried to execute this line
cmd.CommandText = string.Format("[dbo].[search_PIValue] {0},'{1}'", kpi,monthyear);
我收到此错误:
将数据类型nvarchar转换为日期时出错。
我不是知道要改变什么以及在哪里做出改变,因为我是新手程序员。
请帮帮我。
这是我的存储过程:
I got this error:
Error converting data type nvarchar to date.
I don''t know what to change and where to make a change since i''m a newbie programmer.
Please help me.
This is my stored procedure:
ALTER proc [dbo].[search_PIValue]
(
@KPI int,
@monthyear DATE
)
as
begin
select
p.ObjectID,p.PIName,pt.PIvalue
from PItable p
inner join
PITrantbl pt
on
p.ObjectID = pt.PID
where p.KPIid=@KPI and pt.Month=MONTH(@monthyear)
end
推荐答案
假设monthyear
是一个DateTime(看起来它来自你的例子)作为参数传递它而不是转换它:
Assuming thatmonthyear
is a DateTime (and it looks like it is from your example) pass it through as a Parameter instead of converting it at all:
cmd.CommandText = string.Format("[dbo].[search_PIValue] {0},@MY", kpi);
cmd.Parameters.AddWithValue("@MY", monthyear);
然后SQL应该自行排序。
SQL should then sort it all out itself.
这篇关于将数据类型nvarchar转换为日期时出错。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文