[help]按日期更正WHERE的语法

编程入门 行业动态 更新时间:2024-10-12 05:53:09
本文介绍了[help]按日期更正WHERE的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我不知道语法的部分 我希望我的表单通过使用b_date自动加载来自数据库的数据 但仅显示记录如果月份和日期匹配 不使用年份,该程序就像生日提醒

私人 Sub Form1_Load( ByVal sender As System。对象, ByVal e 作为 System.EventArgs)句柄 MyBase .Load ' TODO:这行代码将数据加载到'Bene_dbDataSet.bene_records'表中。您可以根据需要移动或删除它。 我 .Bene_recordsTableAdapter.Fill(我 .Bene_dbDataSet.bene_records) con = 新 OleDb.OleDbConnection dbProvider = Provider = Microsoft.Jet.OLEDB.4.0; dbSource = 数据源= C:\Users\RedemptorisMater \Desktop\S\K..\WindowsApplication1 \ WindowsApplication1 \bene_db.mdb 如果 不 con.State = ConnectionState.Open 然后 con.Open() 结束 如果 Dim da As OleDb.OleDbDataAdapter Dim Sql As 字符串 ' '这就是部分我不知道语法, ' '我希望我的表单自动加载来自数据库的数据 ' '使用b_date但仅显示记录月份和日期匹配 ' '未使用年份,该计划就像一个生日提醒 Sql = SELECT * FROM bene_records da = 新 OleDb.OleDbDataAdapter(Sql,con) Dim dt 作为 新 DataTable da.Fill(dt) con.Close() 结束 Sub

解决方案

请阅读我对解决方案的评论1 我建议这样查询:

PARAMETERS [mnth] INT ; SELECT < FieldList> FROM bene_records WHERE b_date BETWEEN #DateSerial(年份(日期()),[mnth], 1 )# AND #DateSerial(年份(日期()),[mnth] +1,1-1)#

以上查询应返回给定月份的数据(从第一天到最后一天)。 替换< FieldList> 包含要返回的列集。如果您关心性能,请不要将 * 与 SELECT 语句一起使用。 要调用它,您需要设置 OledbParameter [ ^ ] vs.90%29.aspx> OledbCommand [ ^ ]。 更多: DateSerial(MS Access查询) [ ^ ] 数据类型(MS Access) [ ^ ]

尝试:

SELECT * FROM bene_records WHERE DATEPART(mm,GETDATE ())= DATEPART(mm,dateColumn) AND DATEPART(dd,GETDATE())= DATEPART(dd,dateColumn)

This is the part that I dont know the syntax I want that my form automatically loads the data from the Database by using the b_date but only display the records if there is a match in month and date not using the year, The program is like a Birthday Reminder

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'Bene_dbDataSet.bene_records' table. You can move, or remove it, as needed. Me.Bene_recordsTableAdapter.Fill(Me.Bene_dbDataSet.bene_records) con = New OleDb.OleDbConnection dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0;" dbSource = "Data Source = C:\Users\RedemptorisMater\Desktop\S\K..\WindowsApplication1\WindowsApplication1\bene_db.mdb" If Not con.State = ConnectionState.Open Then con.Open() End If Dim da As OleDb.OleDbDataAdapter Dim Sql As String ''THIS IS THE PART THAT I DONT KNOW THE SYNTAX, ''I want that my form automatically loads the data from the Database ''by using the b_date but only display the records if theres a match in month and date ''not using the year, The program is like a Birthday Reminder Sql = "SELECT * FROM bene_records" da = New OleDb.OleDbDataAdapter(Sql, con) Dim dt As New DataTable da.Fill(dt) con.Close() End Sub

解决方案

Please, read my comment to the solution 1 I'd suggest query like this:

PARAMETERS [mnth] INT; SELECT <FieldList> FROM bene_records WHERE b_date BETWEEN #DateSerial(Year(Date()), [mnth], 1)# AND #DateSerial(Year(Date()), [mnth]+1, 1-1)#

Above query should return data for given month (from first to last day). Replace <FieldList> with set of columns you want to return. Do not use * together with SELECT statement, if you care about performance. To call this, you need to set OledbParameter[^] for OledbCommand[^]. More: DateSerial (MS Access query)[^] Data Types (MS Access)[^]

Try:

SELECT * FROM bene_records WHERE DATEPART(mm, GETDATE()) = DATEPART(mm, dateColumn) AND DATEPART(dd, GETDATE()) = DATEPART(dd, dateColumn)

更多推荐

[help]按日期更正WHERE的语法

本文发布于:2023-11-22 06:07:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616259.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法   按日

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!