我是编程和使用的新手SQL Server Compact
,我正在做这个个人项目来学习,所以非常感谢任何帮助。
我试图隐藏成功登录button
的Main Form
取决于用户类型的帐户。
在我的数据库中,我有 3 列,它们username
是password
和type - (this is what I am trying to access for this project)
。
我认为要获得我想要的效果,我必须处理 Main_load 所以这是我放置此代码的地方:
private void Main_Load(object sender, EventArgs e)
{
admincontrolbtn.Visible = false;
conn = new SqlCeConnection("Data Source=Users.sdf; Persist Security Info = False");
comm = new SqlCeCommand("Select * from [user]", conn);
reader = comm.ExecuteReader();
while (reader.Read())
{
try
{
conn.Open();
if (reader.GetString(2) == "Administrator")
{
admincontrolbtn.Visible = true;
}
else
{
admincontrolbtn.Visible = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
}
}
当我构建代码时,没有发现错误。我以为我走在正确的轨道上。但是,当我使用具有 的凭据登录时User" type
,button
仍然可见。我已经尝试通过在Main_load
自身上放置一个中断来调试代码,但是当我运行它并登录时,它会显示主页,完全忽略 Main_load。
我还尝试将属性的可见性设置button
为 false,但是当主页加载时,即使使用管理员类型的凭据,也会button
保持隐藏状态。
代码的语法错了吗?和/或也许我的思维方式Main_load
是我的目标错误?