使用ExecuteAsync
适用于创建,插入等,但不适用于选择。这是两个有效的查询:CREATE TABLE t(x INTEGER PRIMARY KEY ASC, y, z)
和insert into t(y, z) values(2, 2)
但是选择没有。这是我的代码:
SQLiteAsyncConnection conn = new SQLiteAsyncConnection(App.Databaselocation);
var result = await conn.ExecuteAsync("select y from t");
并抛出此SQLiteException:
SQLite.SQLiteConnection.Execute(System.String查询,System。)中的SQLite.SQLiteException:在SQLite.SQLiteCommand.ExecuteNonQuery()[0x000ad]中的行\ n,位于/Users/vagrant/git/src/SQLite.cs:2334 \ n中。 /Tesers/vagrant/git/src/SQLite.cs:673 \ n中的Object [] args)[0x0003a]位于/ Users / vagrant / git / src / SQLiteAsync中的SQLite.SQLiteAsyncConnection + <> c__DisplayClass21_0.b__0()[0x00013] .cs:222 \ n在System.Threading.Tasks.Task
1[TResult].InnerInvoke () [0x0000f] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 \n at System.Threading.Tasks.Task.Execute () [0x00010] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 \n at System.Runtime.CompilerServices.TaskAwaiter
1 [TResult] .GetResult()[0x00000] in:0 \ n atou.PoblacionPage + d _1.MoveNext()[0x00044] in C:\ Users \ sgmon \ OneDrive \ Projects \ Mars \ Pob.xaml.cs:41“
您需要使用Query / QueryAsync来从sql select返回结果集:
var result = await conn.QueryAsync<t>("select y from t");