我有一个包含列的列表视图:
ID,Contact_Name,Contact_Number,DateAndTime,Messages
我想使用"日期"来搜索列表视图。在DateAndTime专栏中。
使用textbox_textChanged:
Try
Dim sqlQuery As String = "SELECT From SentItems WHERE DateAndTime like '%" & TextBox6.Text & "%'"
Dim sqlCommand As New OleDbCommand
Dim sqlAdapter As New OleDbDataAdapter
Dim Table As New DataTable
With sqlCommand
.CommandText = sqlQuery
.Connection = cn
End With
With sqlAdapter
.SelectCommand = sqlCommand
.Fill(Table)
End With
lvSent.Items.Clear()
For i = 0 To Table.Rows.Count - 1
With lvSent
.Items.Add(Table.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(Table.Rows(i)("Contact_Name"))
.Add(Table.Rows(i)("Contacts_Number"))
.Add(Table.Rows(i)("DateAndTime"))
.Add(Table.Rows(i)("SentMessage"))
.Add(Table.Rows(i)("Status"))
End With
End With
Next
Catch ex As Exception
End Try
textbox6中的日期格式= M / d / yyyy
listview中的日期格式= M / d / yyyy
问题是每次我搜索并找到(匹配的)结果。列表视图中的所有项目甚至与文本框中的文本都不匹配。请帮帮我们......谢谢....
答案 0 :(得分:1)
像这样更改您的查询
Dim dt as string
dt=Format(CDate(TextBox6.Text),"yyyy-MM-dd")
Dim sqlQuery As String = "SELECT From SentItems WHERE DateAndTime like '%" & Format(CDate(dt),"yyyy-MM-dd") & "%'"