I restricted some menus in the window forms I created with menustrip for users. The restrictions I set manually work just fine. But I want to put and remove the constraints using checkboxes in the form

instead of putting them manually. But my codes cannot pull constraints from database. I am using access database. I will be glad if you help.
if I do like this it works :
if (yetkim == "1")
{
sabitBilgilerToolStripMenuItem.Enabled = true;
kitapIslemleriToolStripMenuItem.Enabled=treu;
üyeIslemleriToolStripMenuItem.Enabled = true;
kitapAlisVerisiToolStripMenuItem.Enabled = true;
raporlarToolStripMenuItem.Enabled = true;
ayarlarToolStripMenuItem.Enabled = true;
güvenliÇikisToolStripMenuItem.Enabled = true;
}
else
{
sabitBilgilerToolStripMenuItem.Enabled = false;
kitapIslemleriToolStripMenuItem.Enabled = false;
üyeIslemleriToolStripMenuItem.Enabled = false;
kitapAlisVerisiToolStripMenuItem.Enabled = true;
raporlarToolStripMenuItem.Enabled = false;
ayarlarToolStripMenuItem.Enabled = false;
güvenliÇikisToolStripMenuItem.Enabled = true;
kitapIslemleriToolStripMenuItem.Enabled = true;
but this doesn't work :
if (yetkim == "1")
{
sabitBilgilerToolStripMenuItem.Enabled = true;
kitapIslemleriToolStripMenuItem.Enabled = true;
üyeIslemleriToolStripMenuItem.Enabled = true;
kitapAlisVerisiToolStripMenuItem.Enabled = true;
raporlarToolStripMenuItem.Enabled = true;
ayarlarToolStripMenuItem.Enabled = true;
güvenliÇikisToolStripMenuItem.Enabled = true;
}
else
{
OleDbDataAdapter adap = new OleDbDataAdapter("SELECT akatad FROM altkatagori", conn);
DataTable tbl = new DataTable();
adap.Fill(tbl);
}

Tuhin PaulPosted Mar 22, 2023, 1:33 AM
you can modify your code like this. The menu items must have the same name as the values in the "akatad" column in the "altkatagori" table for this code to work.
Mehmet FatihPosted Mar 22, 2023, 9:49 AM
Thank you very much for your attention Tuhin. The problem was solved.
Tuhin PaulPosted Mar 22, 2023, 1:32 AM
Hello Mehmet ,
In your second code snippet, you are only executing a database query to retrieve data from the "altkatagori" table, but you are not setting the enabled/disabled state of the menu items based on the result of the query.