按日期和时间选择,参数不匹配错误 [英] Select by date and time, parameters mismatch Error

查看:75
本文介绍了按日期和时间选择,参数不匹配错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个表,其中包含字段Logid(primery key),名称,地址,EnteranceTime,LeaveTime
我想访问离开时间为空"和进入时间与当前时间的差小于我指定的持续时间"的记录.我正在尝试将当前时间和持续时间作为函数参数传递.问题是我无法正确传递参数.错误是参数不匹配.
SELECT登录ID,名称,地址,公司,EnteranceTime,LeaveTime,CardId
从EnteranceLog
(LeaveTime为NULL)和( EnteranceTime-?=?)
在C#中,我以这种方式调用查询

TimeSpan timespan = getduration();
this.enteranceLogMissingPersonsTableAdapter.Fill(this.enteranceLogDataSet.EnteranceLogMissingPersons,DateTime.Now.ToString(),timespan.ToString());
请指导我如何克服此错误

Hi Everybody,
I have a table with the fields Logid(primery key), Name, Address,EnteranceTime,LeaveTime
I want to access the records where the ''leavetime is null'' and ''difference of Enterance time and the current time is less than the time duration I specify''. I am trying to pass current time and the time duration as function parameters. Problem is I can''t pass the parameters right way. The error is parameters mismatch.
SELECT Logid, Name, Address, Company, EnteranceTime, LeaveTime, CardId
FROM EnteranceLog
WHERE (LeaveTime IS NULL) AND (EnteranceTime - ? = ?)
In c# I am calling the query this way

TimeSpan timespan = getduration();
this.enteranceLogMissingPersonsTableAdapter.Fill(this.enteranceLogDataSet.EnteranceLogMissingPersons, DateTime.Now.ToString (), timespan.ToString () );
please guide me how can I overcome this error

推荐答案

当您传递参数时,必须转换参数值...
如果您创建表并定义列,例如
cur_time timestamp数据类型然后...
首先,您创建对象

SqlCommand cmd =新的SqlCommand();
cmd.parameter.add("date",sqldbtype.timestamp);


我希望您会得到一些帮助
when u pass to parameter you must convert the parameter value...
like if u create a table and define column like
cur_time timestamp datatype then ...
first you create the object

SqlCommand cmd = new SqlCommand();
cmd.parameter.add("date",sqldbtype.timestamp);


i hope might you got some selp


您应该在SQL中使用DateDiff函数.在代码中,只需传递持续时间即可.您可以通过SQL中的GetDate获取当前日期和时间.
You should use the DateDiff function in your SQL. In the code, just pass the duration. You can get the current date and time through GetDate in SQL.


这篇关于按日期和时间选择,参数不匹配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆