System.FormatException: 输入字符串的格式不正确是什么错误?
过程体:
public string D_GetMaxBM(string ParentBM)
{
string sql;
string ResultStr;
ResultStr="";
int ResultStrlen;
int tResultStr;
int Plen=ParentBM.Length+1; //得到父类编号长度并加1,因为多一个 “-”
string tempP=ParentBM+"-"; //父类编号后面加上一个“-”
sql="select max(substr(BM,"+ Plen +",length(BM))) as BM from CL_CKCB where BM like '"+ tempP.ToString() +"%'";
DataTable temptb=this.ListBySql(sql);
string maxBM = temptb.Rows[0]["BM"].ToString();
if(maxBM!=null)
{
tResultStr=System.Convert.ToInt32(temptb.Rows[0]["BM"].ToString())+1; //取得最大值+1
}
else
{
tResultStr=1 ;
}
ResultStr=tResultStr.ToString();
ResultStrlen=ResultStr.Length;
if(ResultStrlen< 3)
{
for(int i=0;i< 3-ResultStrlen;i++)
{
ResultStr="0"+ResultStr.ToString();
}
}
else
{
ResultStr=ResultStr;
}
return ResultStr; //返回
}
调用运行报错:
输入字符串的格式不正确。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.FormatException: 输入字符串的格式不正确。
源错误:
行 41: if(maxBM!=null)
行 42: {
行 43: tResultStr=System.Convert.ToInt32(temptb.Rows[0]["BM"].ToString())+1; //取得最大值+1
行 44: }
行 45: else
请问这个是什么错误啊,我已经判断了maxBM是不是为null了啊,怎么还是报这个错了?
还请各位指点