Func query()
$txt0 = GUICtrlRead($input1);输入查询条件
$txt1 = GUICtrlRead($Combo1);*
$txt2 = GUICtrlRead($Combo2);table name
$txt3 = GUICtrlRead($Combo3);字段
$txt4 = GUICtrlRead($Combo4);like or =
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path)
$RS =ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
Dim $fieldname,$match
If $txt3 = "厂别" Then $fieldname = "plant"
If $txt3 = "设备编号" Then $fieldname = "equipment_number"
If $txt3 = "风险级别" Then $fieldname = "danger_level"
If $txt3 = "资产编号" Then $fieldname = "asset_number"
If $txt3 = "风险级别" Then
$RS.open("select "&$txt1&" from "&$txt2&" where "&$fieldname& "= "&$txt0&"")
;这里需要一个语句,返回查询得到的行数赋值给$view3,这个语句如何写啊?
GUICtrlSetData($Label5,$view3)
Else
$RS.open("select "&$txt1&" from "&$txt2&" where "&$fieldname& "= '"&$txt0&"'")
EndIf
$i = 0
while Not $RS.eof And Not $RS.bof
if @error =1 Then ExitLoop
GUICtrlCreateListViewItem($RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value&"|"& $RS.Fields (3).value&"|"& $RS.Fields (4).value&"|"& $RS.Fields (5).value&"|"& $RS.Fields (6).value&"|"& $RS.Fields (7).value&"|"& $RS.Fields (8).value&"|"& $RS.Fields (9).value&"|"& $RS.Fields (10).value&"|"& $RS.Fields (11).value,$ListView3)
$i = $i + 1
$rs.movenext
WEnd
If $i= 0 then
MsgBox(0,"提示","无数据返回!请确认输入!")
EndIf
EndFunc
有两个问题需要请教大大:
1.select查询时,字段名+关系运算符+字段值。当字段值为string时,需要加单引号,为数字是不需要加,虽然我写的能够运行,但那是把它分成两种情况,感觉很幼稚,有没有更好的办法啊
2.$RS.open("select "&$txt1&" from "&$txt2&" where "&$fieldname& "= "&$txt0&"")
;这里需要一个语句,返回查询得到的行数赋值给$view3,这个语句如何写啊?
GUICtrlSetData($Label5,$view3)
[ 本帖最后由 qqgghh1 于 2009-4-7 16:35 编辑 ] |