代码访问的SQLite没有表? [英] SQLite accessed by code has no tables?

查看:19
本文介绍了代码访问的SQLite没有表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 SQLiteManager 创建了一个 SQLite 数据库.我有一张名为 Envelopes 的表和其他表.当我从代码(如下)访问它时,我收到一个异常,说我试图访问的表不存在.我试过 Envelopes 和 ZVDB.Envelopes,是的,我仔细检查了表名的拼写.

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.Remainder;
    cmd.Parameters.Add("@3", DbType.Int32).Value = env.Budget;

    env.ID = (int) cmd.ExecuteScalar();
}

我的 MonoDevelop 项目中有它,并设置了正确的操作.

I have it in my MonoDevelop project, set with the proper action.

推荐答案

这表示数据库路径错误.

This means the path to the database is wrong.

在 SQLite 中,当您打开一个不存在的数据库时,默认情况下它只会创建一个空白的新数据库.没有错误.

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.

在连接字符串中,您只指定了没有路径的 ZVDB.尝试指定完整的绝对路径.

In the connection string you specified simply ZVDB with no path. Try specifying a full absolute path.

这篇关于代码访问的SQLite没有表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆