WHERE子句的DBUtils.ExecuteListView参数不起作用

时间:2011-11-19 16:53:34

标签: basic4android

我想使用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))

1 个答案:

答案 0 :(得分:1)

更新 - 解决问题:

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

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