这是它给的错误,我的Biz代码以及存储过程都很好,没有“ strCity”变量,一切都很好,但是当我添加此添加项的那一刻,给我带来了麻烦
txtCityName.Text = null;
string strVal = hdnOption.Value;
IFormatProvider provider = new System.Globalization.CultureInfo("en-GB", true);
DateTime dtStart = new DateTime();
DateTime? dtEnd = null;
string strCity;
if (strVal == "today")
{
HideCustomSearch();
dtStart = DateTime.Today;
dtEnd = DateTime.Today;
strCity = txtCityName.Text.ToString().Trim();
}
if (strVal == "weekly")
{
HideCustomSearch();
dtStart = DateTime.Now.AddDays(-7).Date;
dtEnd = DateTime.Today;
strCity = txtCityName.Text.ToString().Trim();
}
if (strVal == "byweekly")
{
HideCustomSearch();
dtStart = DateTime.Now.AddDays(-15).Date;
dtEnd = DateTime.Today;
strCity = txtCityName.Text.ToString().Trim();
}
if (strVal == "monthly")
{
HideCustomSearch();
dtStart = DateTime.Now.AddMonths(-1).Date;
dtEnd = DateTime.Today;
strCity = txtCityName.Text.ToString().Trim();
}
if (strVal == "yearly")
{
HideCustomSearch();
dtStart = DateTime.Now.AddYears(-1).Date;
dtEnd = DateTime.Today;
strCity = txtCityName.Text.ToString().Trim();
}
if (strVal == "custom")
{
ShowCustomSearch();
dtStart = DateTime.Now;
dtEnd = DateTime.Now;
strCity = txtCityName.Text.ToString().Trim();
strCity = null;
hdndtStart.Value = txtdtStart.ToString();
hdndtEnd.Value = txtdtEnd.Text.ToString();
}
FillGridFilter(dtStart, dtEnd, strCity);
PS其仅在最后一行“ strCity”上给我错误
更好的是,在调用之前,在您的条件逻辑中分配null
给strCity
,else if
而不是使用,if
并测试其是否strCity
为null FillGridFilter
。
从中可以看出,strVal变量的所有可能选项都是互斥的,因此无需在每次测试中都强制对其进行重新评估。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句