我想从SQLite数据库[C#]中获取单个值
我试图从sqlite数据库中获取单个值,但遇到了错误 所以我可以对这个值做一些操作或者检查它我想从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
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
?