Xamarin C#中对Sqlitie DB的异步原始查询中的选择问题

时间:2018-09-06 15:15:09

标签: c# sqlite xaml xamarin async-await

使用ExecuteAsync可以创建,插入等,但不能用于select。 这是两个有效的查询: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.SQLiteException:第\ n行   SQLite.SQLiteCommand.ExecuteNonQuery()[0x000ad]在   /Users/vagrant/git/src/SQLite.cs:2334 \ n at   SQLite.SQLiteConnection.Execute(System.String查询,System.Object []   args)/Users/vagrant/git/src/SQLite.cs:673 \ n在[0x0003a]   SQLite.SQLiteAsyncConnection + <> c__DisplayClass21_0.b__0   ()在/Users/vagrant/git/src/SQLiteAsync.cs:222 \ n中的[0x00013]   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 at   Byou.PoblacionPage + d__1.MoveNext   ()[0x00044] in   C:\ Users \ sgmon \ OneDrive \ Projects \ Mars \ Pob.xaml.cs:41   “

1 个答案:

答案 0 :(得分:0)

您需要使用Query / QueryAsync才能从sql select返回结果集:

var result = await conn.QueryAsync<t>("select y from t");