[英]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.