[己解决]SQLite 数据库如何多列与循环查询?
本帖最后由 chzj589 于 2016-11-5 10:54 编辑SQLite 数据库如何多列与循环查询?
学习操作SQLite 数据库的读取、写入、修改、查询、Excel导入。
现在不能多列查询,
如SQLite 数据库有同样的数据,不能循环查询显示在ListView列表?
下面的代码如何修改?
Func _ButtonSelect()
$Strn1 = GUICtrlRead($GUI_InputName)
If $Strn1 = "" Then
MsgBox(0, "错误提示", "查询不能为空")
ThisInputClear()
Else
SQLiteSelect($TableName, $Name, GUICtrlRead($GUI_InputName))
EndIf
EndFunc ;==>_ButtonSelect
;输入参数:1。表名2.记录名3.记录的值
Func SQLiteSelect($TableName, $key, $keyValue)
If GUICtrlRead($GUI_InputName) = '' Then
MsgBox(48, "提示", "请输入搜索名称", 3)
Else
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($DListView1))
GUICtrlSendMsg($DListView1, $LVM_DELETEALLITEMS, 0, 0)
$readq19 = GUICtrlRead($GUI_InputName)
_SQLite_Open($SQLite_Data_Path)
_SQLite_QuerySingleRow(-1, "SELECT * FROM " & $TableName & " WHERE " & $key & " = '" & $keyValue & "';", $aRow)
_GUICtrlListView_AddItem($DListView1, $aRow)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 1)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 2)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 3)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 4)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 5)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 6)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 7)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 8)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 9)
;MsgBox(262208, "查找结果...", "找到记录: 编号[" & $aRow & "] 姓名[" & $aRow & "] 年龄[" & $aRow & "] !")
;#ce
EndIf
_SQLite_Close()
EndFunc ;==>SQLiteSelect
请kk_lee69 兄弟帮忙
问题己经解决!谢谢kk_lee69 兄弟 回复 1# chzj589
很不错啊,贴完整的我学习学习。我刚把写入弄的差不多了。 回复 1# chzj589
发现帮助里的列子几乎都不能正常的运行{:face (197):} 回复 1# chzj589
Func SQLiteSelect($TableName, $key, $keyValue)
If GUICtrlRead($GUI_InputName) = '' Then
MsgBox(48, "提示", "??入搜索名?", 3)
Else
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($DListView1))
GUICtrlSendMsg($DListView1, $LVM_DELETEALLITEMS, 0, 0)
$readq19 = GUICtrlRead($GUI_InputName)
_SQLite_Open($SQLite_Data_Path)
_SQLite_Query(-1, "SELECT * FROM " & $TableName & " WHERE " & $key & " = '" & $keyValue & "';", $hQuery)
While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
_GUICtrlListView_AddItem($DListView1, $aRow)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 1)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 2)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 3)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 4)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 5)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 6)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 7)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 8)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 9)
WEnd
;MsgBox(262208, "查找?果...", "找到??: ??[" & $aRow & "] 姓名[" & $aRow & "] 年?[" & $aRow & "] !")
;#ce
EndIf
_SQLite_Close()
EndFunc ;==>SQLiteSelect 回复 1# chzj589
上面範例 應該是改成多筆資料 可以顯示....譬如 符合條件的 有五筆五筆就都會秀出來
至於 你要 多個欄位 可以 下條件篩選這是 Where 的問題
只要將Where組合成Where 欄位1 = 條件1AND 欄位2=條件2 AND 欄位3=條件3
這樣的字串 帶入 SQL 語法中 就可以了 回复 5# kk_lee69
用:
_GUICtrlListView_AddItem($DListView1, $aRow)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 1)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 2)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 3)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 4)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 5)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 6)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 7)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 8)
_GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow), $aRow, 9)
不能显示,
用GUICtrlCreateListViewItem($aRow & "|" & $aRow & "|" & $aRow & "|" & $aRow, $DListView1)
才能显示,不知为什么?
谢谢!己经解决! 回复 4# kk_lee69
For $i = 1 to 500
_SQLite_Exec($hDb, "INSERT INTO settings (key,value) VALUES (" & $i & "," & $i & ")")
这个添加变量进去有点绕,增加一个 就出错。这个貌似只能添加到数据库100其余的不循环。 回复 7# heroxianf
增加一個甚麼東西
甚麼叫做添加到數據庫100
其餘的不循環?? 回复 8# kk_lee69
我就是想同时添加多个值到数据库,增加一个引号就不知道如何使用了。上边的循环添加只添加到 $i = 100就没添加了
回复 8# kk_lee69
{:face (197):}自己没仔细观察都添加进去了。要翻页才能看到~ {:face (411):}
页:
[1]