命令文本中的日期条件 [英] Date Condition in command text

查看:64
本文介绍了命令文本中的日期条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期格式是yyyy-mm-dd

mycommandtext是''select * from myTable where issate> =''" &

Me.txtStartDate.text& "''和issated< =''" &安培; Me.txtEndDate.text& "''"


它返回零记录,是命令文本是否有错误?

非常感谢

解决方案




两件事。首先将日期括在#和第二个我相信

日期必须是mm / dd / yyyy格式。


Dim strDate As String = Me。 txtStartDate.text

Dim dt As Date = Date.ParseExact(strDate," yyyy-mm-dd",New

Globalization.CultureInfo(" en-US))


从myTable中选择*,其中authorate> =#" &

dt.toshortdatestring& #和issate< =#" &安培; dt.toshortdatestring&安培; "#"

Ken

---------------------

Agnes < AG *** @ dynamictech.com.hk>写在消息

新闻:u7 ************** @ TK2MSFTNGP12.phx.gbl ...

我的日期格式是yyyy-mm-dd

mycommandtext是''select * from myTable where issuedate> =''" &

Me.txtStartDate.text& "''和issated< =''" &安培; Me.txtEndDate.text& "''"


它返回零记录,是命令文件有错误吗?

非常感谢





两件事。首先将日期括在#和第二个我相信

日期必须是mm / dd / yyyy格式。


Dim strDate As String = Me。 txtStartDate.text

Dim dt As Date = Date.ParseExact(strDate," yyyy-mm-dd",New

Globalization.CultureInfo(" en-US))


从myTable中选择*,其中authorate> =#" &

dt.toshortdatestring& #和issate< =#" &安培; dt.toshortdatestring&安培; "#"

Ken

---------------------

Agnes < AG *** @ dynamictech.com.hk>写在消息

新闻:u7 ************** @ TK2MSFTNGP12.phx.gbl ...

我的日期格式是yyyy-mm-dd

mycommandtext是''select * from myTable where issuedate> =''" &

Me.txtStartDate.text& "''和issated< =''" &安培; Me.txtEndDate.text& "''"


它返回零记录,是命令文件有错误吗?

非常感谢


"艾格尼丝" < AG *** @ dynamictech.com.hk> schrieb:

我的日期格式是yyyy-mm-dd
mycommandtext是''select * from myTable where issuedate> =''" &
Me.txtStartDate.text& "''和issated< =''" &安培; Me.txtEndDate.text& "''"




使用参数而不是手动汇总SQL命令字符串

防止SQL注入:


< URL:http://groups.google.de/groups?selm = eb11vcS0DHA.2604%40TK2MSFTNGP09.phx.gb l>


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< ;网址:http://dotnet.mvps.org/dotnet/faqs/>


my date format is in yyyy-mm-dd
mycommandtext is ''select * from myTable where issuedate >=''" &
Me.txtStartDate.text & "'' and issuedate <= ''" & Me.txtEndDate.text & "'' "

It return zero records, Is that the commandtext got errors ??
Thanks a lot

解决方案

Hi,

Two things. First enclose the date in # and second i believe the
date has to be in mm/dd/yyyy format.

Dim strDate As String = Me.txtStartDate.text

Dim dt As Date = Date.ParseExact(strDate, "yyyy-mm-dd", New
Globalization.CultureInfo("en-US"))

select * from myTable where issuedate >= #" &
dt.toshortdatestring & "# and issuedate <= #" & dt.toshortdatestring& "# "
Ken
---------------------
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
my date format is in yyyy-mm-dd
mycommandtext is ''select * from myTable where issuedate >=''" &
Me.txtStartDate.text & "'' and issuedate <= ''" & Me.txtEndDate.text & "'' "

It return zero records, Is that the commandtext got errors ??
Thanks a lot


Hi,

Two things. First enclose the date in # and second i believe the
date has to be in mm/dd/yyyy format.

Dim strDate As String = Me.txtStartDate.text

Dim dt As Date = Date.ParseExact(strDate, "yyyy-mm-dd", New
Globalization.CultureInfo("en-US"))

select * from myTable where issuedate >= #" &
dt.toshortdatestring & "# and issuedate <= #" & dt.toshortdatestring& "# "
Ken
---------------------
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
my date format is in yyyy-mm-dd
mycommandtext is ''select * from myTable where issuedate >=''" &
Me.txtStartDate.text & "'' and issuedate <= ''" & Me.txtEndDate.text & "'' "

It return zero records, Is that the commandtext got errors ??
Thanks a lot


"Agnes" <ag***@dynamictech.com.hk> schrieb:

my date format is in yyyy-mm-dd
mycommandtext is ''select * from myTable where issuedate >=''" &
Me.txtStartDate.text & "'' and issuedate <= ''" & Me.txtEndDate.text & "'' "



Use parameters instead of putting together the SQL command string by hand to
prevent SQL injection:

<URL:http://groups.google.de/groups?selm=eb11vcS0DHA.2604%40TK2MSFTNGP09.phx.gb l>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


这篇关于命令文本中的日期条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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