找回密码
 加入
搜索
查看: 4451|回复: 10

[网络通信] [己解决]SQLite 数据库如何多列与循环查询?

  [复制链接]
发表于 2016-10-30 10:08:09 | 显示全部楼层 |阅读模式
本帖最后由 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[0])
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[1], 1)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[2], 2)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[3], 3)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[4], 4)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[5], 5)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[6], 6)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[7], 7)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[8], 8)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[9], 9)

                ;MsgBox(262208, "查找结果...", "找到记录: 编号[" & $aRow[0] & "] 姓名[" & $aRow[1] & "] 年龄[" & $aRow[2] & "] !")
        ;#ce
        EndIf
        _SQLite_Close()
EndFunc   ;==>SQLiteSelect

请kk_lee69 兄弟帮忙

问题己经解决!谢谢kk_lee69 兄弟

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-10-30 11:30:35 | 显示全部楼层
回复 1# chzj589


    很不错啊,贴完整的我学习学习。我刚把写入弄的差不多了。
发表于 2016-10-30 11:34:10 | 显示全部楼层
回复 1# chzj589


发现帮助里的列子几乎都不能正常的运行
发表于 2016-10-30 12:41:57 | 显示全部楼层
回复 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[0])
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[1], 1)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[2], 2)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[3], 3)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[4], 4)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[5], 5)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[6], 6)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[7], 7)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[8], 8)
                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[9], 9)
                WEnd
                ;MsgBox(262208, "查找?果...", "找到??: ??[" & $aRow[0] & "] 姓名[" & $aRow[1] & "] 年?[" & $aRow[2] & "] !")
        ;#ce
        EndIf
        _SQLite_Close()
EndFunc   ;==>SQLiteSelect
发表于 2016-10-30 12:49:52 | 显示全部楼层
回复 1# chzj589

上面範例 應該是改成多筆資料 可以顯示....譬如 符合條件的 有五筆  五筆就都會秀出來

至於 你要 多個欄位 可以 下條件篩選  這是 Where 的問題

只要將  Where  組合成  Where 欄位1 = 條件1  AND 欄位2=條件2 AND 欄位3=條件3   

這樣的字串   帶入 SQL 語法中 就可以了
 楼主| 发表于 2016-10-30 13:35:25 | 显示全部楼层
回复 5# kk_lee69
用:
               _GUICtrlListView_AddItem($DListView1, $aRow[0])

                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[1], 1)

                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[2], 2)

                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[3], 3)

                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[4], 4)

                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[5], 5)

                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[6], 6)

                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[7], 7)

                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[8], 8)

                _GUICtrlListView_AddSubItem($DListView1, _GUICtrlListView_FindInText($DListView1, $aRow[0]), $aRow[9], 9)
不能显示,
用GUICtrlCreateListViewItem($aRow[0] & "|" & $aRow[1] & "|" & $aRow[2] & "|" & $aRow[3], $DListView1)
才能显示,不知为什么?
谢谢!己经解决!
发表于 2016-10-30 16:06:16 | 显示全部楼层
回复 4# kk_lee69

For $i = 1 to 500
_SQLite_Exec($hDb, "INSERT INTO settings (key,value) VALUES (" & $i & "," & $i & ")")

   
这个添加变量进去有点绕,增加一个 就出错。  这个貌似只能添加到数据库100  其余的不循环。
发表于 2016-10-30 16:12:55 | 显示全部楼层
回复 7# heroxianf

增加一個甚麼東西

甚麼叫做添加到數據庫100

其餘的不循環??
发表于 2016-10-30 16:16:07 | 显示全部楼层
回复 8# kk_lee69

我就是想同时添加多个值到数据库,增加一个  引号就不知道如何使用了。  上边的循环添加  只添加到 $i = 100  就没添加了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-10-30 16:19:13 | 显示全部楼层
回复 8# kk_lee69

  自己没仔细观察  都添加进去了。  要翻页才能看到~
发表于 2016-11-5 17:28:01 | 显示全部楼层
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 18:55 , Processed in 0.084780 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表