anyone can help me please!
i have a problem in coding...
i want to restrict some buttons of my form if the user is not a admin
i already tried this code..

sql = "SELECT Position FROM tbllogin WHERE username = "txtUsername.text""
NewDataSet(sql)
if .ds.Tables("a").Rows.Count= "Administrator" Then
employeeFile.btnDelete.Enabled = True
else
employeeFile.btnDelete.Enabled = False
End if

but it doesnt work please anyone can help here

At the top of your code type this:

Option Strict On

Better yet, on the menu got Tools->Options. Expand the "Projects and Solutions" node. Select "VB Defaults" and turn it on there.

This will allow Visual Studio to point you to many mistakes in your code.

Look at this line:
if .ds.Tables("a").Rows.Count= "Administrator" Then
What does:.ds.Tables("a").Rows.Count return? (Hint: an integer value)
Will an integer value ever be equal to the string "Administrator"?

Also, your SQL statement is probably not well-formed. You should be concatenating the literal with TWO SINGLE-quotes and a couple of concatenation symbols

It should look like this (assuming MSSQL is your dbms):

sql = "SELECT Position from tblLogin WHERE username = ''" & txtUsername.text & "''"

Not quite correct. The select should be

sql = "SELECT Position from tblLogin WHERE username = '" & txtUsername.text & "'"

and somewhere, sometime, somehow, someone is going to mention how you should be using parameter entry instead of concatenation to protect against SQL injection attacks.

commented: You're right, good catch. On both items :-) +8
if .ds.Tables("a").Rows.Count > 0 Then 

???

change your sql statement

sql = "SELECT Position FROM tbllogin WHERE username = ' " & txtUsername.text & " ' "
NewDataSet(sql)
if .ds.Tables("a").Rows.Count= "Administrator" Then
employeeFile.btnDelete.Enabled = True
else if ds.tables("a").Rows.Count <> "Administrator" Then
employeeFile.btnDelete.Enabled = False
End if

. hope it works

if .ds.Tables("a").Rows.Count= "Administrator" Then

will never evalualte to True because it is comparing an integer to a string. In English, the code is saying "if the number of rows equals Administrator"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.