VB数据库ADO怎么查询多个字段并定位到那个字段?
比如要定位到符合“年”=2012、“月”=2、“日”=2的那条数据上去,怎么定位,用Adodc1.Recordset.find还是Adodc1.Recordset.Fil...
比如要定位到符合“年”=2012、“月”=2、“日”=2的那条数据上去,怎么定位,用Adodc1.Recordset.find还是Adodc1.Recordset.Filter,后者好像是筛选出符合的数据没定位吧??!用什么语句才能定位到呢???
展开
3个回答
展开全部
例子一个:请先参考一个实际代码;但愿对你有帮助!!
--------------------------
Set RS3 = New ADODB.Recordset
DT1 = Format(Trim(D1.Value), "yyyy-mm-dd")
DT2 = Format(Trim(D2.Value), "yyyy-mm-dd")
If DT1 = DT2 Then MsgBox "正确方法,应选择<日期的区间>后,再进行【开始查询】,OK!!", vbOKOnly, "操作提示": Exit Sub
' ##按;日期;数据;字符三种类型检索//=#" & DT0 & "#///WHERE (((LP_001.被保险人名称) Like "*安*"));
If Txt_TJ.Text = "" Then MsgBox "应填好【查询条件】,再点击【开始查询】按钮!!!", vbOKOnly, "操作提示": Exit Sub
If ComboCX.Text = "船员分类" Then
Txt_TJ.Text = Trim(UCase(Txt_TJ.Text)) & "%"
sSQL = " Select * From Bg_L_IOMX Where (((Bg_L_IOMX.分类) Like '" & Txt_TJ.Text & "')) and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
If ComboCX.Text = "船名" Then
sSQL = " Select * From Bg_L_IOMX where " & ComboCX.Text & " = '" & Txt_TJ.Text & "' And 出数量<>0 and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
If ComboCX.Text = "工号" Then
Txt_TJ.Text = Trim(UCase(Txt_TJ.Text)) & "%"
sSQL = " Select * From Bg_L_IOMX where ((Bg_L_IOMX.ID) Like '" & Txt_TJ.Text & "') and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
If ComboCX.Text = "姓名" Then
Txt_TJ.Text = Trim(UCase(Txt_TJ.Text)) & "%"
sSQL = " Select * From Bg_L_IOMX where ((Bg_L_IOMX.领用人) Like '" & Txt_TJ.Text & "') and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
If ComboCX.Text = "派遣号" Then
'Text1.Text = "【派遣号】可采用<精确>方式,注:组合=船名第1个字+上船时间的XXXX月日;进行【条件查询】!"
sSQL = " Select * From Bg_L_IOMX where " & ComboCX.Text & " = '" & Txt_TJ.Text & "'And 出数量<>0 and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
-----------------------
注明:一定在窗体中定义.
Option Explicit
Dim DT1, DT2 As Variant
--------------------------
Set RS3 = New ADODB.Recordset
DT1 = Format(Trim(D1.Value), "yyyy-mm-dd")
DT2 = Format(Trim(D2.Value), "yyyy-mm-dd")
If DT1 = DT2 Then MsgBox "正确方法,应选择<日期的区间>后,再进行【开始查询】,OK!!", vbOKOnly, "操作提示": Exit Sub
' ##按;日期;数据;字符三种类型检索//=#" & DT0 & "#///WHERE (((LP_001.被保险人名称) Like "*安*"));
If Txt_TJ.Text = "" Then MsgBox "应填好【查询条件】,再点击【开始查询】按钮!!!", vbOKOnly, "操作提示": Exit Sub
If ComboCX.Text = "船员分类" Then
Txt_TJ.Text = Trim(UCase(Txt_TJ.Text)) & "%"
sSQL = " Select * From Bg_L_IOMX Where (((Bg_L_IOMX.分类) Like '" & Txt_TJ.Text & "')) and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
If ComboCX.Text = "船名" Then
sSQL = " Select * From Bg_L_IOMX where " & ComboCX.Text & " = '" & Txt_TJ.Text & "' And 出数量<>0 and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
If ComboCX.Text = "工号" Then
Txt_TJ.Text = Trim(UCase(Txt_TJ.Text)) & "%"
sSQL = " Select * From Bg_L_IOMX where ((Bg_L_IOMX.ID) Like '" & Txt_TJ.Text & "') and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
If ComboCX.Text = "姓名" Then
Txt_TJ.Text = Trim(UCase(Txt_TJ.Text)) & "%"
sSQL = " Select * From Bg_L_IOMX where ((Bg_L_IOMX.领用人) Like '" & Txt_TJ.Text & "') and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
If ComboCX.Text = "派遣号" Then
'Text1.Text = "【派遣号】可采用<精确>方式,注:组合=船名第1个字+上船时间的XXXX月日;进行【条件查询】!"
sSQL = " Select * From Bg_L_IOMX where " & ComboCX.Text & " = '" & Txt_TJ.Text & "'And 出数量<>0 and 日期>='" & DT1 & "' and 日期<='" & DT2 & "' Order by 编号"
End If
-----------------------
注明:一定在窗体中定义.
Option Explicit
Dim DT1, DT2 As Variant
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询