2011-09-06 278 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。 –

相關問題