2011-09-06 277 views
0

我从下面的代码得到以下错误:从数据类型为nvarchar到VARBINARY(最大)从数据类型为nvarchar到VARBINARY(最大)隐式转换不允许

隐式转换是不允许的。使用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

你的sproc是什么样的? –

+2

你似乎正在向数据库发送一个字符串值,你确定它不应该是一个字节数组? – Tejs

+3

我看到你在使用'ArrayList',只觉得脏。 –

回答

0

那么,你传递的图像作为一个AnsiString数据类型,这是问题发生的地方。

我想你需要DbType.Binary。

但是,那么你的参数名是imageFilePath,所以大概你应该给它一个字符串的文件路径?这可能意味着你的xp实际上是错误的。

+0

是Iam使用字符串FileName – Indra

+0

您可以修改我上面发布的代码吗? – Indra

+0

我们确实需要使用扩展proc的代码。我的猜测是你需要将图像复制到可用于sql服务器的本地或网络路径,然后将该路径传递给proc。 –

相关问题