我正在做一个小项目,用户可以在应用程序首次启动时登录应用程序,效果很好。我想为具有 isAdmin 属性的用户添加一种方法,以便能够创建可以访问应用程序的新帐户。
到目前为止,我通过将用户输入到文本框 (this.txt_enterAdmin.Text) 的文本来搜索数据库表“employeeinfo”,以确定用户是否有权创建更多帐户,然后,如果用户在场在“employeeinfo”中,他们可以在表格中输入新的用户名和密码。
这也很好用。我的问题是我不希望任何用户都能够创建新帐户,我想要管理员,并且只有管理员能够这样做。我不确定如何使用硬编码的是/否来搜索数据库。我添加了一个名为“isAdmin”的列,然后使用“文本”数据类型在 SQLite 数据表中为每个用户分配“是”或“否”。
这是我的代码,请看一下:
private void txt_add_newuser_Click(object sender, RoutedEventArgs e)
{
//logic to connect to database, search for the administrator password, and if the data is correct, then create a new user that can use the application.
SQLiteConnection sqliteCon = new SQLiteConnection(dbConnectionString);
sqliteCon.Open();
string YES = "select * from employeeinfo where isAdmin='" + + "' ";
string Query = "select * from employeeinfo where password='" + this.txt_enterAdmin.Text + "' and isAdmin= '" + this.YES + "' ";
SQLiteCommand createCommand = new SQLiteCommand(Query, sqliteCon);
我不确定如何为 YES/NO 值定义字符串,因为我没有从面向用户的控件中提取数据。
您看到我也可以解决的任何反馈或任何错误也将不胜感激。谢谢你。
BIG阳
相关分类