本文介绍了我想从数据库中选择未来15天的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作门通过期的应用程序

所以在主要表格中我放了一个数据网格视图,数据网格视图将显示未来1个月到期门通行证的数据



i写下面的代码,但它显示了未来2个月即将到期的门票清单





请帮助



我的尝试:



私有子MDIParent1_Load(发件人作为对象,e作为EventArgs)处理MyBase.Load

expiryalert()

结束子

Public Sub expiryalert()

尝试

Dim da As New SqlDataAdapter

Dim ds As New DataSet

Dim cmd作为SqlCommand

connection()

cmd =新的SqlCommand(select * from gatepassdetails where expiry>'& Format(Today.AddMonths(1),MM) / dd / yyyy)&',connsql)

d a.SelectCommand = cmd

da.Fill(ds,gatepassdetails)

data_expired.DataSource = ds

data_expired.DataMember =gatepassdetails

Catch ex As Exception

MsgBox(ex.Message.ToString)

connsql.Close()

结束尝试

结束Sub

i am making an app for gate pass expiry
so in main form i put one data grid view the data grid view will show the data of expiring gate passes in next 1 month

i write the below code but it is showing the list of gate passes which are going to expire in next 2 months also


please help

What I have tried:

Private Sub MDIParent1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
expiryalert()
End Sub
Public Sub expiryalert()
Try
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim cmd As SqlCommand
connection()
cmd = New SqlCommand("select * from gatepassdetails where expiry > '" & Format(Today.AddMonths(1), "MM/dd/yyyy") & "'", connsql)
da.SelectCommand = cmd
da.Fill(ds, "gatepassdetails")
data_expired.DataSource = ds
data_expired.DataMember = "gatepassdetails"
Catch ex As Exception
MsgBox(ex.Message.ToString)
connsql.Close()
End Try
End Sub

推荐答案


cmd = New SqlCommand("SELECT * FROM gatepassdetails WHERE expiry < DATEADD(mm, 1, GETDATE())", connsql)

保留它所有内部SQL。

Which keeps it all inside SQL.


这篇关于我想从数据库中选择未来15天的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 23:35