如何判断数据库操作以后返回object 类型的值为NULL
若有以下代码操作存储过程:
SqlCommand borrowbook=new SqlCommand();
borrowbook.Connection=this.sqlConnection1;
borrowbook.CommandType=CommandType.StoredProcedure;
borrowbook.CommandText="dbo.StoredProcedureBookNumber";
SqlParameter parinput=borrowbook.Parameters.Add("@BookID",SqlDbType.Char);
parinput.Direction=ParameterDirection.Input;
parinput.Value=BookID;
SqlParameter paroutput=borrowbook.Parameters.Add("@BookNumber",SqlDbType.Int);
paroutput.Direction=ParameterDirection.Output;
try
{
this.sqlConnection1.Open();
borrowbook.ExecuteNonQuery();
this.sqlConnection1.Close();
if ( paroutput.Value!=DBNull.Value )
return Convert.ToInt16(paroutput.Value);
else
return -1;
}
catch(System.Exception e)
{
this.ErrorHandle(e);
this.sqlConnection1.Close();
return 0;
}

浙公网安备 33010602011771号