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'
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:(object)filename);
{
YeWuAttachment.Value= DBNull.value;
}else
{
YeWuAttachment.Value= filename;}
但就簡化了那樣寫就是不行,搞不明白!因此才有上面一問!
那是什麼原因呢?
==============
1。 ? A:B. A和B的类型必须一致。
我开始把 B的类型改成了object ,这句通过了,但与 参数的Varchar类型又不一致了。所以还是分开写。