**尝试运行App时,我收到错误:
SQLite错误:没有这样的列:ImageName
它显示了getItems()处的行错误,其中显示:
var r = contents.ExecuteReader();
任何人都知道我的错误在哪里?
**
if (!exists) {
connection = new SqliteConnection ("Data Source=" + dbPath);
connection.Open ();
var commands = new[] {
"CREATE TABLE [Items] (_id INTEGER PRIMARY KEY ASC, Date NTEXT,
Amount NTEXT, Supplier NTEXT,
ImageName NTEXT, AdditionalInfo NTEXT);"
};
foreach (var command in commands) {
using (var c = connection.CreateCommand ()) {
c.CommandText = command;
var i = c.ExecuteNonQuery ();
}
}
} else {
// already exists, do nothing.
}
Console.WriteLine (output);
}
/// <summary>Convert from DataReader to Note object</summary>
Note FromReader (SqliteDataReader r) {
var t = new Note ();
t.ID = Convert.ToInt32 (r ["_id"]);
t.Date = r ["Date"].ToString ();
t.Amount = r ["Amount"].ToString ();
t.Supplier = r ["Supplier"].ToString ();
t.ImageName = r ["ImageName"].ToString ();
t.AdditionalInfo = r ["AdditionalInfo"].ToString ();
return t;
}
public IEnumerable<Note> GetItems ()
{
var tl = new List<Note> ();
lock (locker) {
connection = new SqliteConnection ("Data Source=" + path);
connection.Open ();
using (var contents = connection.CreateCommand ()) {
contents.CommandText = "SELECT [_id], [Date],
[Amount], [Supplier], [ImageName],
[AdditionalInfo] from [Items]";
var r = contents.ExecuteReader ();
while (r.Read ()) {
tl.Add (FromReader(r));
}
}
connection.Close ();
}
return tl;
}