如何检查vb.net和sql之间的日期值 [英] How to check date values between vb.net and sql
本文介绍了如何检查vb.net和sql之间的日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在sql server中有Date字段
I has Date field in sql server
fieldname Type
Billdate datetime
我要保存日期和时间.所以我在vb.net中给出了日期的插入查询
I want save date and Time. So i give the insert query for date in vb.net
Datetime.Now.Tostring
当我从该数据库获取报告时,出现了一些问题.我得到了选定日期之间的记录.但它不会显示.我给出以下编码''
And the when i get the report from that database there is some problem. I get the records between selected dates. But it will not display. i give following coding''
select Billno,Billdate,PName,Qty,TName from CancelOrder where Convert(varchar,Billdate,101) >= ''" & Format(dp1.Value, "MM-dd-yyyy") & "'' and Convert(varchar,Billdate,101)<=''" & Format(dp2.Value, "MM-dd-yyyy") & "''", Cn)
请任何机构帮助获取两个日期之间的记录
Please any body help get records between two dates
推荐答案
在您的sql命令中使用参数!
尝试这样的事情:
Use Parameters in your sql command!
Try something like this:
Dim table As New DataTable()
Dim query As String = "select Billno,Billdate,PName,Qty,TName from CancelOrder where @Billdate1 >= @Billdate2"
Using cn As New SqlConnection(Configuration.DefaultConnectionString)
Using cmd As New SqlCommand(query.ToString(), cn)
cmd.Parameters.Add("@Billdate1", SqlDbType.DateTime).Value = Billdate1
cmd.Parameters.Add("@Billdate2", SqlDbType.DateTime).Value = Billdate2
cn.Open()
Using reader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
table.Load(reader)
End Using
End Using
End Using
您还可以在Google上搜索以下使用sqlcommand参数的vb.net".
干杯
You can also Google the following "vb.net using sqlcommand parameters".
Cheers
通过以下方式替换您的查询
从CancelOrder中选择Billno,Billdate,PName,Qty,TName,其中Billdate> =''&Format(dp1.Value," MM-dd-yyyy)&"''和Billdate< ="&Format( dp2.Value,"MM-dd-yyyy")和'',Cn)
祝你好运
快乐编码
Hi,
replace ur query by following
select Billno,Billdate,PName,Qty,TName from CancelOrder where Billdate >= ''" & Format(dp1.Value, "MM-dd-yyyy") & "'' and Billdate <=''" & Format(dp2.Value, "MM-dd-yyyy") & "''", Cn)
best luck
Happy Coding
这篇关于如何检查vb.net和sql之间的日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文