English 中文(简体)
不允许从数据类型Nvarchar到albinary(最大)进行合法转换。
原标题:Implicit conversion from data type nvarchar to varbinary(max) is not allowed
  • 时间:2011-09-06 19:21:55
  •  标签:
  • c#
  • tsql

我从以下法典中看到以下错误:

不允许从数据类型Nvarchar到albinary(最大)进行合法转换。 利用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);
}

我的程序涉及用户 页: 1

我需要改变哪些数据类型?

问题回答

顺便说一句,你将这一形象作为正在出现问题的异常数据类型。

我认为你需要DbType。 原文。

But then, your parameter name is imageFilePath, so presumably you should actually be giving it a path to a file as a string? This could mean your xp is actually wrong.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签