1
我想使用EditText
框中的值来过滤ListView
。WHERE子句的DBUtils.ExecuteListView参数不起作用
你能看看我的编码,并让我知道我还需要做些什么才能使它工作?
到目前为止它只返回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子句以查看它是否执行任何操作。 –