【发布时间】:2019-06-06 21:58:25
【问题描述】:
我正在尝试编写如下这样的函数来将记录插入到我数据库中的表中。我为此使用 SQLite。我在这 3 行有问题:
insertSQL.Parameters.Add(newUser.Username);
insertSQL.Parameters.Add(newUser.Password);
insertSQL.Parameters.Add(newUser.Email);
错误内容:
错误 CS1061 'SQLiteCommand' 不包含 >'Parameters' 的定义,并且找不到接受“SQLiteCommand”类型的 >first 参数的可访问扩展方法“Parameters”(您是否缺少 >using 指令或程序集参考?)
我有类似“使用 SQLite;使用静态 SQLite.SQLiteCommand;”之类的用法。 Microsoft 文档和许多指南都包含属性“Parameters”和类似代码。
public static SQLiteConnection non_async_db;
public void AddUser(User newUser, string login, string password, string email)
{
SQLiteCommand insertSQL = new SQLiteCommand(non_async_db);
insertSQL.CommandText = "INSERT INTO User(Username, Password, Email) VALUES(" + login + ", " + password + ", " + email + ")";
insertSQL.Parameters.Add(newUser.Username);
insertSQL.Parameters.Add(newUser.Password);
insertSQL.Parameters.Add(newUser.Email);
}
我不知道问题出在哪里。也许这种方式已经过时或完全错误?
【问题讨论】:
-
您阅读过有关使用 SQLite.net 的文档吗? github.com/praeclarum/sqlite-net
标签: c# sqlite xamarin android-sqlite sqlite-net