SQLite accessed by code has no tables?
I created a SQLite database via SQLiteManager. I have a table called Envelopes, and other tables. When I access it from code (below) I get an exception saying that the table I'm trying to access doesn't exist. I've tried both Envelopes and ZVDB.Envelopes, and yes I've double checked my spelling of table names.
var conn = new SqliteConnection("Data Source=ZVDB");
using ( var cmd = conn.CreateCommand()) {
conn.Open();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Envelopes (Name, Remainder, Budget) values (@1, @2, @3); select @@identity";
cmd.Parameters.Add("@1", DbType.String).Value = env.Name;
cmd.Parameters.Add("@2", DbType.Int32).Value = env.R开发者_如何学JAVAemainder;
cmd.Parameters.Add("@3", DbType.Int32).Value = env.Budget;
env.ID = (int) cmd.ExecuteScalar();
}
I have it in my MonoDevelop project, set with the proper action.
This means the path to the database is wrong.
In SQLite when you open a database that doesn't exist, by default it will just create a blank new one. No error.
When you then try to read or write to a table that doesn't exist, you get the error you described.
In the connection string you specified simply ZVDB with no path. Try specifying a full absolute path.
Samuel's answer is correct - if you want to access the database you need to ensure that you've included the database in your solution, set the 'build action' to "Content" and set 'Copt to output directory' to "Always copy".
精彩评论