本帖最后由 xyhqqaa 于 2012-4-10 08:29 编辑
新手求助,,刚接触数据库。。。。比如,我新建数据库查询资料、、。。我的想法是单击输入框。。但是在输入框输入相关信息后需要回车后才在listview中显示。清空输入框的同时清空listview。。。现在遇到的问题是。我在输入框输入数字的时候,就自动已经在listview显示数据了。。。而且是重复不间断输出重复信息。。。。。。。偶尔会卡死。。。囧 。。代码大概如下#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
Dim $ServerIP = '*******', $ServerID = 'sa', $ServerPwd = '', $ServerDatabase = '****'
$Form1 = GUICreate("Form1", 348, 229, 331, 226)
$Input1=GUICtrlCreateInput("", 3, 8, 342, 21)
$ListView1 = GUICtrlCreateListView("工号 |姓名 |部门 ", 3, 32, 225, 193)
$ListView2 = GUICtrlCreateListView("账号 ", 231, 32, 113, 193)
Dim $AccelKeys[2][2] = [["{Enter}", $Input1]]
GUISetAccelerators($AccelKeys)
GUISetState()
#EndRegion ### END Koda GUI section ###
AdlibRegister("_del")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_PRIMARYUP
$CursorInfo = GUIGetCursorInfo()
If $CursorInfo[4] = 3 Then GUICtrlSetData($Input1, "")
Case $nMsg = $Input1
_read()
EndSwitch
WEnd
Func _del()
$number = GUICtrlRead($Input1)
If $number = "" Then
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
EndIf
EndFunc
Func _read()
$number = GUICtrlRead($Input1)
If $number <> "" Then
$conn = ObjCreate("ADODB.Connection")
$RS = ObjCreate("ADODB.Recordset")
$conn.Open("driver={SQL Server};server=" & $ServerIP & ";uid=" & $ServerID & ";pwd=" & $ServerPwd & ";database=" & $ServerDatabase)
$RS.ActiveConnection = $conn
$RS.Open("SELECT *, *, SP FROM * WHERE (S61BH LIKE '%" & $number & "%') OR (SP LIKE '%" & $number & "%') order by * desc")
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, $ListView1)
$RS.movenext
WEnd
$RS.close
$conn.close
EndIf
EndFunc ;==>_read
|