我想获取特定时间范围内的所有条目。我有一个名为“Date”的列,它只存储像“2024-05-01”这样的日期。例如,我想从表“Touurs”中获取从 2023-01-01 到 2023-05-10 的所有条目。
我正在搜索并尝试了几个小时,但没有找到解决方案。
我已经尝试过使用 strftime 但没有成功
为了搜索日期,我像这样创建了 SQLite 数据库 注意:当我在支票簿程序中输入数据时,我仅使用 txYear 和 txSearchMonth 这些值不是通过从今天的日期中提取的来输入的 Dim create_table As String = String.Empty create_table = "如果不存在则创建表 TxData( TID 整数不为空主键自动增量, txSortDate 文本, txYear 整数, tx类型文本, 交易金额文本, txCKNum 文本, tx描述文本, tx余额文本, txSearchMonth 整数)"
这是我使用下拉组合框来选择搜索信息的搜索例程 前缀为 gv 的变量是在 DataModule 中定义的全局变量,请阅读有关模块的信息,它仅在 VB.Net 中可用,而不是 C#
Private Sub ViewSearches()
Dim intID As Integer
Dim strDate As String
Dim strTxType As String
Dim strAmt As Decimal
Dim strCKNum As String
Dim strDesc As String
Dim strBal As Decimal
Dim rowCount As Integer
Dim maxRowCount As Integer
Dim emptyStr As String = " "
Using conn As New SQLiteConnection($"Data Source = '{gv_dbName}';Version=3;")
conn.Open()
Using cmd As New SQLiteCommand("", conn)
If gvSearchType = "All" Then
cmd.CommandText = "SELECT * FROM TxData"
ElseIf gvSearchType = "MoRangeYr" Then
cmd.CommandText = "SELECT * FROM TxData WHERE txSearchMonth >= $gvFromMonth AND txSearchMonth <= $gvToMonth AND txYear = $gvYear "
'cmd.CommandText = "SELECT * FROM TxData WHERE txSearchMonth BETWEEN $gvFromMonth AND $gvToMonth AND txYear = $gvYear "
cmd.Parameters.AddWithValue("$gvFromMonth", gvFromMonth)
cmd.Parameters.AddWithValue("$gvToMonth", gvToMonth)
cmd.Parameters.AddWithValue("$gvYear", gvYear)
ElseIf gvSearchType = "MoYr" Then
cmd.CommandText = "SELECT * FROM TxData WHERE txSearchMonth = $gvFromMonth AND txYear = $gvYear "
cmd.Parameters.AddWithValue("$gvFromMonth", gvFromMonth)
cmd.Parameters.AddWithValue("$gvYear", gvYear)
ElseIf gvSearchType = "TxMoYr" Then
cmd.CommandText = "SELECT * FROM TxData WHERE txType = $gvTxType AND txSearchMonth = $gvFromMonth AND txYear = $gvYear "
cmd.Parameters.AddWithValue("$gvTxType", gvTxType)
cmd.Parameters.AddWithValue("$gvFromMonth", gvFromMonth)
cmd.Parameters.AddWithValue("$gvYear", gvYear)
ElseIf gvSearchType = "Year" Then
cmd.CommandText = "SELECT * FROM TxData WHERE txYear = $gvYear"
cmd.Parameters.AddWithValue("$gvYear", gvYear)
End If