DBNull,教"大家"!
string filename= " ";
if(myFile.PostedFile.ContentLength> 0)
{
string NM=myFile.PostedFile.FileName;
int i=NM.LastIndexOf( ". ");
string extNM=NM.Substring(i);
filename= "QC "+mid+extNM;
UploadFile(filename);
}
else
{
filename=attachmentLb.Text;//
}
......
SqlParameter YeWuAttachment=new SqlParameter( "@YeWuAttachment ",SqlDbType.VarChar);
YeWuAttachment.Value=(filename==string.Empty?DBNull.Value:filename);
......
什上面代出,怎修正?大家!
:
CSSModify.cs(233,56): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DBNull ' and 'string '
[解决办法]
YeWuAttachment.Value=(filename==string.Empty?DBNull.Value:filename);==> YeWuAttachment.Value=(filename==string.Empty?DBNull.Value:(object)filename);
[解决办法]
?:运算符的后两个值的类型必须相同
[解决办法]
分是可以的。但就化了那就是不行,搞不明白!因此才有上面一!那是什原因呢?==============1。 ? A:B. A和B的类型必须一致。 我开始把 B的类型改成了object ,这句通过了,但与 参数的Varchar类型又不一致了。所以还是分开写。