Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I hide a button in the Main form depending on the person logging in?
    primarykey
    data
    text
    <p>I'm new to programming and using <code>SQL Server Compact</code> and I'm doing this personal project to learn, so any assistance is greatly appreciated. </p> <p>I am trying to hide the <code>button</code> in the <code>Main Form</code> depending on the user type account that successfully logging.</p> <p>In my database i have 3 columns which are <code>username</code>, <code>password</code> and <code>type - (this is what I am trying to access for this project)</code>.</p> <p>I figured that to get the effect that I want I would have to deal with the Main_load so this is where I placed this code:</p> <pre><code> 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(); } } } </code></pre> <p>When I built the code no error was found. I thought that I was on the right track. But when I logged in using a credential that has a <code>User" type</code>, the <code>button</code> was still visible. I have already tried to debug the code by putting a break right on the <code>Main_load</code> itself but when i run it and log in, it goes to display the Main page ignoring the Main_load altogether. </p> <p>I have also tried to set the visibility of the <code>button</code> to false it the properties but when the main page loads, even using the <b>Administrator</b> type of credential, the <code>button</code> stays hidden.</p> <p>Was the syntax of the code wrong? and/or maybe my way of thinking that <code>Main_load</code> is my target wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload