异常详细信息: System.FormatException: 输入字符串的格式不正确。

来源:百度知道 编辑:UC知道 时间:2024/06/13 21:40:35
源错误:

行 165: int unValidate = Convert.ToInt32(jclj.DbBase.BaseDb.exeRetuDs("select kv_value from jc_kv where kv_key='info_dis_time'").Tables[0].DefaultView[0][0].ToString());
-----------------------------------------------------------------
源代码:
string aa = jclj.DbBase.BaseDb.exeRetuDs(strsql).Tables[0].DefaultView[0][0].ToString();
if (aa != "")
{
DateTime dt = Convert.ToDateTime(aa);
int m1 = dt.Month;
int d2 = dt.Day;
int b = m1 * 30 + d2;
int m = DateTime.Now.Month;
int d = DateTime.Now.Day;
int a = m * 30 + d;
int unValidate = Convert.ToInt32(jclj.DbBase.BaseDb.exeRetuDs("select kv_value from jc_kv where kv_key='info_dis_time'").Tables[0].DefaultView[0][0].ToString());
if (a - b

把第二个方法改一下,添中一个条件判断,因为command1.ExecuteScalar();有可能返回一个DbNull.Value,所以如下:
public class sql
{
public string Getvalue(string strsql)
{
SqlCommand command1;
object obj1;
string text1 = "err";
SqlConnection connection1 = new SqlConnection(.....);
try
{
connection1.Open();
command1 = new SqlCommand(strsql, connection1);
obj1 = command1.ExecuteScalar();
if (obj1 != null && obj1 != DBNull.Value)
{
text1= obj1.ToString();
}
}
catch
{
return text1;
}
finally
{
connection1.Close();
}
return text1;
}
}