Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想从SQLite数据库[C#]中获取单个值_C#_Sqlite - Fatal编程技术网

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

我想从SQLite数据库[C#]中获取单个值,c#,sqlite,C#,Sqlite,我试图从sqlite数据库中获取单个值,但遇到了错误 所以我可以对这个值做一些操作或者检查它 dbConnection StartConn = new dbConnection(); SQLiteConnection MyConnetion = StartConn.GetConnection(); SQLiteCommand Cm = new SQLiteCommand(" select * from Users where user_usern

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

所以我可以对这个值做一些操作或者检查它

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();


您的dtareader没有行,这会导致错误。试着这样做:

if(dr.Read())
{
    // rest of your code
}

globalVariables
似乎为空。此上下文中是否存在
globalVariables