【问题标题】:DBUtils.ExecuteListView parameter for the WHERE clause is not workingWHERE 子句的 DBUtils.ExecuteListView 参数不起作用
【发布时间】:2011-11-20 07:45:53
【问题描述】:

我想使用EditText 框中的值来过滤ListView

你能看看我的编码,让我知道我还需要做什么才能让它工作吗?

到目前为止它只返回 0 行。

Sub ButtonSearchFilterEventHandler_Click
  ' Populate the list.
  '-------------------
  DBUtils.ExecuteListView(SQL, "SELECT Id, ResultDescription " & _
    "FROM VisitResultTypes " & _
    "WHERE ResultDescription = ? " & _
    "ORDER BY ResultDescription", _
    Array As String(EditTextResultDescription.Text), 0, _
    ListViewResults, True)
End Sub

附加子程序:

Sub Activity_Create(FirstTime As Boolean)
  SQL.ExecNonQuery("CREATE TABLE VisitResultTypes " & _
    "(Id INTEGER PRIMARY KEY, ResultDescription TEXT)")
End Sub

这个有效。它显示所有表格行:

Sub PopulateTheListView
 ' Populate the list.
 '-------------------
 DBUtils.ExecuteListView(SQL, "SELECT Id, ResultDescription " & _
    "FROM VisitResultTypes " & _    
    "ORDER BY ResultDescription", _
    Null, 0, ListViewResults, True)
End Sub

我试过了,但无论我在 EditText 框中输入什么,它都会返回所有行:

Sub ButtonSearchFilterEventHandler_Click
  ' Populate the list.
  '-------------------
  DBUtils.ExecuteListView(SQL, "SELECT Id, ResultDescription " & _
    "FROM VisitResultTypes " & _
    "WHERE ResultDescription LIKE ? " & _
    "ORDER BY ResultDescription", _
    Array As String(EditTextResultDescription.Text & "%"), 0, _
    ListViewResults, True)
End Sub

这个将数据添加到表中:

SQL.ExecNonQuery2("INSERT INTO VisitResultTypes " & _ 
  "(Id, ResultDescription) " & _
  "VALUES " & _
  "(?, ?)", Array As Object(Null, EditTextResultDescription.Text))

【问题讨论】:

  • 您的代码似乎没问题,据我所见。您确定您传递的ResultDescription 存在,并且它们完全相同吗? (您使用的是= 而不是LIKE 与通配符,因此嵌入或尾随空格之类的内容可能很重要-我还不熟悉SQLite。)您能否编辑您的问题以添加所用列的数据库定义在您的查询中,以及一些行的样本和您用作参数的值?
  • 当然。我会先尝试一下“LIKE”关键字,看看是否可行。
  • 我添加了数据库定义编码。希望你能发现我的错误。我将尝试使用参数进行查询并添加我自己的 WHERE 子句以查看它是否有任何作用。
  • 请查看本文顶部的更新。我通过添加另一个 TextEdit 框并将调用更改为 ExecuteListView 来实现。
  • 干得好。我赞成你原来的问题。您是否知道,经过足够的时间后,您可以将自己的答案与解决方案一起发布并接受?这让人们知道它已得到更清楚的回答。

标签: basic4android


【解决方案1】:

更新 - 问题已解决:

我添加了另一个 EditText 框并使用它来使过滤工作:

DBUtils.ExecuteListView(SQL, "SELECT Id, ResultDescription " & _
  "FROM VisitResultTypes " & _
  "WHERE ResultDescription LIKE " & "'" & EditTextSearchFilter.Text & "%' " & _
  "ORDER BY ResultDescription", Null, 0, ListViewResults, True)

【讨论】:

    猜你喜欢
    • 2015-01-27
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2023-03-27
    相关资源
    最近更新 更多