如何在N层应用程序中保存图像? [英] How can i save image in my N-tier application?

查看:67
本文介绍了如何在N层应用程序中保存图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

''在DA_Company中''

''In DA_Company''

Function Company_Save(ByVal M_Model_DA As Model.M_Company) As String
       Try
           connection_enable()
           cmd = New SqlCommand()
           cmd.CommandText = "SP_HR_Company_Insert"
           cmd.Connection = con
           cmd.CommandType = CommandType.StoredProcedure
           cmd.Parameters.Add("@Company_Logo", SqlDbType.Image).Value = M_Model_DA.Company_Logo
           err_message = cmd.ExecuteNonQuery()
       Catch ex As Exception
           err_message = ex.ToString()
       End Try
       Return err_message
   End Function



``在BL_Company中''



''In BL_Company''

Function Company_Save(ByVal M_Company_BL As Model.M_Company) As String
      Try
          DA_Company = New DataAccess.DA_Company()
          error_message = DA_Company.Company_Save(M_Company_BL)
      Catch ex As Exception
          error_message = ex.ToString()
      End Try
      Return error_message
  End Function



``在M_Company中''



''In M_Company''

Public Property Company_Logo() As Byte
       Get
           Return Me.CompanyLogo
       End Get
       Set(ByVal value As Byte)
           Me.CompanyLogo = value
       End Set
   End Property



``在Frm_Company中''



''In Frm_Company''

Private Sub Company_Save()
      Try
          BL_Company = New BusinessLogic.BL_Company()
          M_Comapny = New Model.M_Company()
          M_Comapny.Company_Logo = Convert.ToByte(browseCompanyLogo.Value)
          error_message = BL_Company.Company_Save(M_Comapny)

          If error_message > 0 Then
              MessageBox.Show("Complete Save")
              Company_GridView_FillData()
          End If
      Catch ex As Exception
          MessageBox.Show(ex.Message.ToString())
      End Try





 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        
Company_Save()

    End Sub






但是它表明输入流的格式不正确.为什么 ?请!






But It Shows Input Stream was not in a correct format . Why ? please !

推荐答案

请确保您的SqlDbType.Image或SqlDbType.Binary
You make sure your SqlDbType.Image or SqlDbType.Binary
cmd.Parameters.Add("@Company_Logo", SqlDbType.Image).Value = M_Model_DA.Company_Logo



如果图片
是否需要转换字节



If Image
Will it be need to convert byte

<pre lang="vb">Convert.ToByte(browseCompanyLogo.Value)</pre>


Frm_Company'





希望对您有所帮助,
Theingi.





Hope be helpful,
Theingi.


M_Comapny.Company_Logo = IO.File.ReadAllBytes(browseCompanyLogo.Value.ToString())


这篇关于如何在N层应用程序中保存图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆