[英]Cannot insert null value in varbinary(max) with error : implicit conversion from data type nvarchar to varbinary(max) is not allowed
[英]Implicit conversion from data type nvarchar to varbinary(max) is not allowed
我從下面的代碼中收到以下錯誤:
不允許從數據類型nvarchar隱式轉換為varbinary(max)。 使用CONVERT函數運行此查詢。
protected void btnOKImageUpload_Click(object sender, EventArgs e)
{
try
{
string filePath = "";
string fileName = "";
int UserId = Convert.ToInt32(hdnUserId.Value);
if (fileImage.HasFile)
{
if (CheckFileType(fileImage.FileName))
{
filePath = Server.MapPath(Application["UploadFolder"].ToString());
if (UserId > -1)
{
fileName = "Image_" + UserId.ToString() + Path.GetExtension(fileImage.FileName);
}
else
{
fileName = Path.GetFileName(fileImage.FileName);
}
string virFileName = Application["UploadFolder"].ToString() + "/" + fileName;
string tmpFileName = Path.Combine(filePath, fileName);
fileImage.SaveAs(tmpFileName);
SessionData.LocationFloorPlanFile = tmpFileName;
DataAccess.SaveEmployeeImage(UserId, fileName);
hdnImageFileName.Value = fileName;
txtImageUpload.Text = virFileName;
//btnFloorPlanView.HRef = hdnFloorPlan.Value;
btnImageUpload.Disabled = true;
btnImageDelete.Enabled = true;
hdnPostbackAction.Value = "UPLOAD";
}
}
}
catch (Exception ex)
{
hdnErrMsg.Value = ex.Message;
//"An error has occurred while processing your request. Please contact support for further assistance.";
}
}
public static void SaveEmployeeImage(int userId, string imageFilePath)
{
ArrayList paramaters = getParamArray();
paramaters.Add(getParam("@userId", DbType.Int32, userId));
paramaters.Add(getParam("@imageFilePath", DbType.AnsiString, imageFilePath));
executeNonQuery("xp_SaveEmployeeImage", paramaters);
}
我的過程將userId和圖像插入表中。
我需要更改哪種數據類型?
好吧,您正在將該圖像作為AnsiString數據類型傳遞,這就是問題所在。
我認為您需要DbType.Binary。
但是,然后,您的參數名稱是imageFilePath ,因此大概應該給它一個字符串形式的文件路徑嗎? 這可能意味着您的XP實際上是錯誤的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.