郁闷了
数据库中这个字段是null,
取出来后调试,s= " ";
if (dsCustomer.Tables[0].Rows[0][ "Sex "] != null || dsCustomer.Tables[0].Rows[0][ "Sex "].ToString().Trim() != " " || dsCustomer.Tables[0].Rows[0][ "Sex "].ToString().Length ==0)
{
string s = dsCustomer.Tables[0].Rows[0][ "Sex "].ToString();
ddlSex.SelectedValue = dsCustomer.Tables[0].Rows[0][ "Sex "].ToString();
}
else
{
ddlSex.SelectedValue = "请选择 ";
}
他怎么就走不到else里呢
[解决办法]
dsCustomer.Tables[0].Rows[0][ "Sex "] != null
dsCustomer.Tables[0].Rows[0][ "Sex "].ToString().Trim() != " "
dsCustomer.Tables[0].Rows[0][ "Sex "].ToString().Length ==0
说明以上3个条件有一个为true。
[解决办法]
用个段点看看程序的走向不就得了
[解决办法]
设断点看下
dsCustomer.Tables[0].Rows[0][ "Sex "].ToString().Trim()
它的内容是什么
[解决办法]
||改成&&
if (dsCustomer.Tables[0].Rows[0][ "Sex "] != null && dsCustomer.Tables[0].Rows[0][ "Sex "].ToString().Trim() != " " && dsCustomer.Tables[0].Rows[0][ "Sex "].ToString().Length !=0)
{
string s = dsCustomer.Tables[0].Rows[0][ "Sex "].ToString();
ddlSex.SelectedValue = dsCustomer.Tables[0].Rows[0][ "Sex "].ToString();
}
else
{
ddlSex.SelectedValue = "请选择 ";
}
[解决办法]
数据库中这个字段确实是null吗?还是有空格或回车符?