如何在c#中将String值转换为boolean [英] How to convert String value to boolean in c#
本文介绍了如何在c#中将String值转换为boolean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是从数据库中获取记录并想检查是否存在特定行的记录?我正在尝试下面的一些代码,但错误是无法将bool转换为字符串...
那我怎么能克服这个问题
Hi, I am fetching the record from database and want to check the Whether record for perticular row is present or not? I am trying some code at below ,but error is that cannot convert bool to string...
So how can i overcome this problem
bool chek = DS.Tables["table"].Rows[0]["MB_MobileNo"].ToString().Contains();
if(Chek>0)
{
txtMobileNo.Text = DS.Tables["table"].Rows[0]["MB_MobileNo"].ToString().Substring(3);
}
推荐答案
使用 Boolean.Parse [ ^ ]或 Boolean.TryParse [ ^ ] methods。
Use the Boolean.Parse[^] or Boolean.TryParse[^] methods.
bool check = string.IsNullOrEmpty( Convert.ToString(ds.Tables [table]。Rows [0] [column]));
bool check = string.IsNullOrEmpty( Convert.ToString( ds.Tables["table"].Rows[0]["column"]));
参考
这篇关于如何在c#中将String值转换为boolean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文