Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从VB.Net应用程序中选择SQLite(Win32)_Vb.net_Sqlite - Fatal编程技术网

从VB.Net应用程序中选择SQLite(Win32)

从VB.Net应用程序中选择SQLite(Win32),vb.net,sqlite,Vb.net,Sqlite,我试图从SQL数据库中获取一个结果,并将其作为变量保存。但是对于我的代码(见下文),它返回0(零)。你知道我做错了什么吗 谢谢 Function getName(name As String) Dim SQLconnect As New SQLite.SQLiteConnection() Dim SQLcommand As SQLite.SQLiteCommand SQLconnect.ConnectionString = "Data Source=C:\tools\n

我试图从SQL数据库中获取一个结果,并将其作为变量保存。但是对于我的代码(见下文),它返回0(零)。你知道我做错了什么吗

谢谢

Function getName(name As String)
    Dim SQLconnect As New SQLite.SQLiteConnection()
    Dim SQLcommand As SQLite.SQLiteCommand

    SQLconnect.ConnectionString = "Data Source=C:\tools\names.sqlite;"
    SQLconnect.Open()

    SQLcommand = SQLconnect.CreateCommand

    SQLcommand.CommandText = "SELECT * FROM names WHERE name = " & name & " LIMIT 1;"
    Dim sqlResponse As String = SQLcommand.ExecuteNonQuery()


End Function

编辑:我使用“return sqlResponse”作为return,首先,sql应该是(我认为):

我不确定文本在SQLite中是如何表示的,但您需要某种分隔符,比如SQLServer中的单引号

第二件事,使用参数化查询来阻止自己被SQL注入劫持


第三,SELECT使用ExecuteReader,如果您只需要一个项目,请尝试ExecuteScalar。ExecuteNonQuery用于插入、更新和删除。

执行
非查询
不返回值,因此它将始终为
0
。你需要使用

Dim sqlResponse As String = SQLcommand.ExecuteScalar()

它与ExecuteScalar一起工作!非常感谢!这是正确的答案!
Dim sqlResponse As String = SQLcommand.ExecuteScalar()