使用vb在数据库中查找区间记录

来源:百度知道 编辑:UC知道 时间:2024/04/28 16:07:22
Private Sub Command1_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)

sle = "select 日期,商品名称,所售单价,所售数量,客户名称,业务员工号 from xiaoshou where 日期 between '" & a & "' and '" & b & "'"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = sle
Adodc1.Refresh
If Adodc1.Recordset.RecordCount >= 1 Then
Set DataGrid1.DataSource = Adodc1
Else
MsgBox ("此段时间没有记录")
End If
End Sub

哪里有错误啊,各位大哥,或者说怎末编写 我想在数据库中查找从文本1到文本2之间的记录
我在线等啊,大哥些

Private Sub Command1_Click()
dim a as date
dim b as date
a = Text1.Text
b = Text2.Text

sle = "select 日期,商品名称,所售单价,所售数量,客户名称,业务员工号 from xiaoshou where 日期>=#" & a & "# and 日期<=#" & b & "#"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = sle
Adodc1.Refresh
If Adodc1.Recordset.RecordCount >= 1 Then
Set DataGrid1.DataSource = Adodc1
Else
MsgBox ("此段时间没有记录")
End If
End Sub

"select 日期,商品名称,所售单价,所售数量,客户名称,业务员工号 from xiaoshou where 日期 >= #" & a & "# 日期<= #" & b & "#"