【问题标题】:SQLite Command?SQLite 命令?
【发布时间】:2019-06-15 05:20:48
【问题描述】:

我正在尝试使用 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 个参数的构造函数 我在互联网上查了一下,但我没有得到它,我是新手。

【问题讨论】:

  • what is wrong with my code ...我们不知道,因为您从未告诉我们。请告诉我们问题所在。
  • 您看到了什么错误? “用户”的价值是什么?
  • 抱歉,我编辑了。
  • 您应该停下来阅读有关使用 SQLite 的文档。即使您修复了当前错误,您的代码也无法正常工作。
  • 与您的问题无关,但是...您不应该将密码作为明文存储在数据库中(您的查询是直接访问密码)。

标签: xamarin sqlite.net


【解决方案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;
    }

【讨论】:

  • 谢谢大家。我刚刚解决了问题:)
猜你喜欢
  • 2014-05-28
  • 1970-01-01
  • 2017-05-14
  • 1970-01-01
  • 2014-02-22
  • 2012-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多