【发布时间】:2016-01-20 21:11:43
【问题描述】:
我正在使用 C# 和 SQLite 编写一个 Windows 商店应用程序。在这种情况下,我面临一个问题,我为此寻找解决方案。但我没有运气。问题是 我想从表中删除一条记录。我的桌子是这样的
class DocumentRecord
{
[PrimaryKey, AutoIncrement]
public int dID { get; set; }
public string dName { get; set; }
public string dDescription { get; set; }
public byte[] dImage { get; set; }
public int uID { get; set; }
public string dTextData { get; set; }
public DateTime dCreatedDate { get; set; }
public DateTime dUpdatedDate { get; set; }
}`
我的删除方法如下:
private async void btnDelete_Click(object sender, RoutedEventArgs e)
{
//confirmation();
SQLiteAsyncConnection dbconn = new SQLiteAsyncConnection("Data.db");
var DeleteItem = await dbconn.Table<DocumentRecord>().Where(x => x.dName == (App.Current as App).documentName).FirstOrDefaultAsync();
if (DeleteItem != null)
{
await dbconn.DeleteAsync(DeleteItem);
var dlge = new MessageDialog("You successfully deleted a document !");
await dlge.ShowAsync();
}
}
我发现如下所示的错误:
System.NotSupportedException: Cannot compile: TypeAs at SQLite.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
at SQLite.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
at SQLite.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
at SQLite.TableQuery`1.GenerateCommand(String selectionList)
at SQLite.TableQuery`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at SQLite.TableQuery`1.FirstOrDefault()
at SQLite.AsyncTableQuery`1.<FirstOrDefaultAsync>b__6()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MMUD.LoadFlyout.<btnDelete_Click>d__6.MoveNext()
【问题讨论】:
-
如果您将文本添加为文本而不是图像,则效果会更好,更有用。搜索不会读取图像中的文本。请您努力在您的帖子中的代码块中添加错误文本。感谢您的理解与合作。