xamarin - SQLite 命令?
问题描述
我正在尝试使用 xamarin 制作登录页面
public bool Login(string Username, string Password)
{
Users _user = new Users();
string mySelectQuery = "SELECT Name, Password FROM Users WHERE Name='" + Username + "' AND Password='" + Password + "'";
var user = new SQLiteCommand(mySelectQuery);
if (user != null)
{
return true;
}
return false;
}
在 SQLiteCommand 部分,它给出了一个错误。错误是 CS1729 不包含带有 1 个参数的构造函数,我在互联网上检查了但我没有得到它我是新手。
解决方案
您使用 SQLiteCommand 类,并包含一个参数,它应该是 SQLiteConnection,这是关于此的示例:
public bool Login(string Username, string Password)
{
string dbName = "Data Source=searchindex.db";
string mySelectQuery = "SELECT Count(*) FROM Users WHERE Name='" + Username + "' AND Password='" + Password + "'";
SQLiteConnection con = new SQLiteConnection(dbName);
SQLiteCommand cmd = new SQLiteCommand(con);
cmd.CommandText = mySelectQuery;
var count = cmd.ExecuteScalar<int>();
if (count>0)
{
return true;
}
return false;
}
推荐阅读
- excel - (Excel - power query M) WeekOfYear 不返回好的数字
- gradle - file.getName() 找不到方法 getName() 的符号(使用 Gradle 和 Javalin)
- c - “#Include”出现在C语言的“struct”中
- python - 在 Python 中使用 Iris 读取 NetCDF 文件时不支持的日历
- android - 活动结束后是否必须执行 onPause() ?
- python - 熊猫:我需要将单列分成两列,用逗号分隔
- python - 如何使用 Pandas 列表中的值随机替换列中的值?
- docker - Docker IPtables 链被删除
- php - 使用 PHP 模数在 div 列中排序数组
- python - 在出现时将 Flask 控制台日志写入 HTML 模板