2017-02-24 2 views
0

Ceci est mon bouton mise à jour événement click:J'ai solution cherche pour cela, mais en ayant toujours erreur dans ma requête de mise à jour au moment de l'image télécharger

private void btnUpdate_Click(object sender, EventArgs e) 
     { 
      try 
      { 
       if (ValidateAll()) 
       { 
        SetValues(); 
        _objHotel_EL.HotelID = HotelId; 
        _objHotel_EL.CommandName = "Update_HotelDetails"; 

        int update = _objHotel_BL.Insert_Hotel(_objHotel_EL); 

        if (update > 0) 
        { 
         MessageBox.Show("Hotel Details Updated"); 
         ClearAll(); 
        } 
        else 
        { 
         MessageBox.Show("Already Exists"); 
         ClearAll(); 
        } 
       } 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
     } 

voici mon code qui est utilisé pour définir et télécharger l'image et d'autres paramètres:

private void SetValues() 
     { 
      _objHotel_EL.HotelName = txtHotelName.Text.Trim(); 
      _objHotel_EL.PhoneNo = txtPhoneNo.Text.Trim(); 
      _objHotel_EL.Address = txtAddress.Text.Trim(); 
      _objHotel_EL.EmailId = txtEmailId.Text.Trim(); 
      _objHotel_EL.WebSite = txtWebsite.Text.Trim(); 
      _objHotel_EL.CurrID = CommanValue.CurrID; 

      if (flag == 1) 
      { 
       _objHotel_EL.BinaryImage = ReadFile(labelImagePath.Text); 
       _objHotel_EL.ImagePath = labelImagePath.Text; 
      } 
      else 
      { 
       if (imageData == null) 
       { 
        string path = System.AppDomain.CurrentDomain.BaseDirectory.Replace("\\Debug", ""); 
        path = path.Replace("\\bin", ""); 
        path = path.Replace("\\x86", ""); 
        path = path + "Images\\NoImage1.png"; 
        labelImagePath.Text = path; 
        imageData = ReadFile(labelImagePath.Text); 
        _objHotel_EL.ImagePath = path; 
       } 
       _objHotel_EL.ImagePath = labelImagePath.Text; 
       _objHotel_EL.BinaryImage = (byte[])imageData; 
      } 
     } 

Ceci est du code de ReadFile:

private byte[] ReadFile(string strPath) 
     { 
      byte[] data = null; 
      FileInfo fInfo = new FileInfo(strPath); 
      long numBytes = fInfo.Length; 
      FileStream fstream = new FileStream(strPath, FileMode.Open, FileAccess.Read); 
      BinaryReader br = new BinaryReader(fstream); 
      data = br.ReadBytes((int)numBytes); 
      return data; 
     } 

S'il vous plaît aidez-moi o ut parce que c'est en me donnant une erreur The conversion is not supported. [ Type to convert from (if known) = nvarchar, Type to convert to (if known) = image ] pendant que j'utilise sql server compact dans Visual Studio 2012 en utilisant C#.

Dans la base de données, le type de données de l'image est l'image.

+0

Quel est le type renvoyé de votre fonction * ReadFile *? –

+0

Afficher le code de la méthode ReadFile –

+0

J'ai mis à jour ma question. –

Répondre

0

En fait, j'ai essayé avec moi-même après avoir utilisé SqlCeCommand paramètres et son résolu. Voici le code.

if (objEL.CommandName == "Update_HotelDetails") 
      { 
       DataTable dt = SqlHelper.ExecuteDataset("SELECT HotelName, HotelID FROM Master_Hotel WHERE (HotelName = '" + objEL.HotelName + "') AND (HotelID <> '" + objEL.HotelID + "')").Tables[0]; 
       if (dt.Rows.Count == 0) 
       { 
        string str = ("UPDATE Master_Hotel SET HotelName = @HotelName, PhoneNo = @PhoneNo, Address = @Address, EmailId = @EmailId, Website = @Website, Image = @Image,ImagePath = @ImagePath WHERE (HotelID = @HotelID)"); 

        cmd = new SqlCeCommand(str, SqlHelper.objCon); 

        cmd.Parameters.Add("@HotelName", SqlDbType.NVarChar).Value = objEL.HotelName; 
        cmd.Parameters.Add("@PhoneNo", SqlDbType.NVarChar).Value = objEL.PhoneNo; 
        cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = objEL.Address; 
        cmd.Parameters.Add("@EmailId", SqlDbType.NVarChar).Value = objEL.EmailId; 
        cmd.Parameters.Add("@Website", SqlDbType.NVarChar).Value = objEL.WebSite; 
        cmd.Parameters.Add("@Image", SqlDbType.Image).Value = objEL.BinaryImage; 
        cmd.Parameters.Add("@ImagePath", SqlDbType.NVarChar).Value = objEL.ImagePath; 
        cmd.Parameters.Add("@HotelID", SqlDbType.Int).Value = objEL.HotelID; 
        SqlHelper.objCon.Open(); 
        i = cmd.ExecuteNonQuery(); 
        SqlHelper.objCon.Close(); 
       } 
      }