首页 > 解决方案 > 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 个参数的构造函数,我在互联网上检查了但我没有得到它我是新手。

标签: xamarinsqlite.net

解决方案


您使用 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;
    }

推荐阅读