SQLite 命令?
SQLite Command?
我正在尝试使用 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 Does not contain a constructor that takes 1 arguments
我在网上查了一下,但我没明白我是新手。
你使用 SQLiteCommand class,并且包含一个参数,它应该是 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;
}
我正在尝试使用 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 Does not contain a constructor that takes 1 arguments 我在网上查了一下,但我没明白我是新手。
你使用 SQLiteCommand class,并且包含一个参数,它应该是 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;
}