Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (dt.Rows.Count > 0)
           {
               while (DR1.Read())
               {
                   role = DR1["Permission"].ToString();
                   if (role == "High")
                   {
                       this.Close();
                       admin.Show();
                   }

}



I am using the above code to check for the user permission. If the user permission is high t, then the admin screen should be displayed. The above code is not working. It reads the value "High" from the database as "High. Please suggest a better solution
Posted
Comments
Herman<T>.Instance 23-Jan-13 6:15am    
.Contains() or use linq

Hi,

use .trim() in DR1["Permission"].ToString()

then try. It may help.


RKS
 
Share this answer
 
Comments
Member 9641602 23-Jan-13 7:45am    
thanks Rahul
We can use Select method in DataTable . This method receives a string expression that specifies what rows you want to select. Select makes DataTables act more like small databases. We explore further this method.

 if(table.Select("role == High").count > 0 )  
{
admin.Show();
}


http://www.dotnetperls.com/datatable-select[^]
 
Share this answer
 
v2
try this
C#
if (dt.Rows.Count > 0)
           {
               while (DR1.Read())
               {
                   role = DR1["Permission"].ToString();
                   if (role.Trim() == "High")
                   {
                       this.Close();
                       admin.Show();
                   }

}
 
Share this answer
 
Comments
Member 9641602 23-Jan-13 7:46am    
thank yo so much , the code works fine now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900