如何从数据库中读取字符串值并将其与另一个字符串进行比较 [英] How to read string value from the database and compare it with another string

查看:124
本文介绍了如何从数据库中读取字符串值并将其与另一个字符串进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案





在DR1中使用.trim()[Permission]。ToString()



然后尝试。它可能会有所帮助。





RKS
Hi,

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

then try. It may help.


RKS


我们可以在 DataTable <中使用选择方法/ big>。此方法接收一个字符串表达式,指定要选择的行。选择使DataTables更像小数据库。我们进一步探索这种方法。



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 [ ^ ]


试试这个

try this
if (dt.Rows.Count > 0)
           {
               while (DR1.Read())
               {
                   role = DR1["Permission"].ToString();
                   if (role.Trim() == "High")
                   {
                       this.Close();
                       admin.Show();
                   }

}


这篇关于如何从数据库中读取字符串值并将其与另一个字符串进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆