【问题标题】:Sqlite error near "dasani2": syntax error“dasani2”附近的 Sqlite 错误:语法错误
【发布时间】:2013-10-25 09:28:52
【问题描述】:

我正在使用数据库创建我的第一个应用程序,但出现错误: SQLite error near "dasani2": syntax error ,这是我的数据库结构和第一行:

id    name     lastname   username   password
1     first    second     dasani     dasani2

这是我的程序代码:

SQLiteConnection sqliteCon = new SQLiteConnection(dbConnectionString);
        try
        {
            sqliteCon.Open();
            string Query = "select * from Users where username='" + Vartotojas.Text.Trim() + "'and password'" + Slaptazodis.Text.Trim() + "'";
            SQLiteCommand createCommand = new SQLiteCommand(Query, sqliteCon);

            createCommand.ExecuteNonQuery();
            SQLiteDataReader dr = createCommand.ExecuteReader();
        }

【问题讨论】:

标签: c# sqlite


【解决方案1】:

您缺少 = 符号:

... "'and password = '" + Slaptazodis.Text.Trim() + "'";

附注:您不应该以纯文本形式存储密码。

【讨论】:

  • 是的,我需要使用散列,但现在我只是在学习一切是如何工作的
【解决方案2】:

您错过了密码列中的 = 符号

password='"...

它不是一个插入查询,它是一个选择查询,所以你不需要这个下面的行

        createCommand.ExecuteNonQuery();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-08
    • 2013-08-12
    • 2016-03-12
    • 2020-05-02
    • 2016-01-14
    • 1970-01-01
    相关资源
    最近更新 更多