我想从SQLite数据库[C#]中获取单一值

时间:2019-03-25 15:13:02

标签: c# sqlite

我正在尝试从sqlite数据库中获取单个值,但我遇到了错误

这样我就可以对此值进行一些操作或检查它

a busy cat

dbConnection StartConn = new dbConnection();
            SQLiteConnection MyConnetion = StartConn.GetConnection();

            SQLiteCommand Cm = new SQLiteCommand(" select * from Users where user_username = '" + txtBxUserName.Text + "' and user_password = '" + txtBxPassword.Text + "'", MyConnetion);

            MyConnetion.Open();
            SQLiteDataReader dr = Cm.ExecuteReader();
            dr.Read();

            int count = Convert.ToInt32(Cm.ExecuteScalar());

            if (count != 0)
            {
                globalVariables.userFullName = dr["user_name"].ToString();
                globalVariables.appLoginUser = dr["user_username"].ToString();
                globalVariables.appPasswordUser = dr["user_password"].ToString();
                globalVariables.userPermissions = dr["user_permissions"].ToString();

                mainForm newMainForm = new mainForm();
                newMainForm.Show();
                this.Hide();

                MyConnetion.Close();

1 个答案:

答案 0 :(得分:0)

您的dtareader没有行,多数民众赞成在引起错误。尝试这样:

type inferred = {}