By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

after converting Bitmap back to MemoryStream not saving proper image

P: 7
I have a data grid view,in update button i wrote code like this:


Expand|Select|Wrap|Line Numbers
  1.     Dim cid As Integer
  2.             Dim dtid As Integer
  3.             Dim cmpname As String
  4.             Dim dtname As String
  5.             Dim dtPhone As String
  6.             Dim dtEmail As String
  7.             Dim dtimage As Image
  8.  
  9.  
  10.             For i As Integer = 0 To gv.RowCount - 2
  11.                 ' Dim rv = DirectCast(bSource.Current, DataRowView)
  12.                 Dim rv = DirectCast(gv.Rows(i).DataBoundItem, DataRowView)
  13.                 cid = rv.Row.Field(Of Integer)("Cid")
  14.  
  15.                 dtid = rv.Row.Field(Of Integer)("dtId")
  16.                 cmpname = rv.Row.Field(Of String)("CompanyName")
  17.                 dtname = rv.Row.Field(Of String)("Department")
  18.                 dtPhone = rv.Row.Field(Of String)("Phone")
  19.                 dtEmail = rv.Row.Field(Of String)("Email")
  20.  
  21.                 Using ms As New MemoryStream(rv.Row.Field(Of Byte())("empimage"))
  22.                     dtimage = New Bitmap(ms)
  23.                 End Using
  24.  
  25.                 adapter.UpdateCommand = New SqlCommand("UPDATE CompanyMaster_tbl SET CompanyName = @CompanyName", con.connect)
  26.                 adapter.UpdateCommand = New SqlCommand("update DepartmentMaster_tbl set dtName = @dtName,dtPhone = @dtPhone,dtEmail = @dtEmail,empimage=@dtimage  where dtId=@dtid", con.connect)
  27.                 adapter.UpdateCommand.Parameters.AddWithValue("@Cid", cid)
  28.                 adapter.UpdateCommand.Parameters.AddWithValue("@CompanyName", cmpname)
  29.                 adapter.UpdateCommand.Parameters.AddWithValue("@dtId", dtid)
  30.                 adapter.UpdateCommand.Parameters.AddWithValue("@dtName", dtname)
  31.                 adapter.UpdateCommand.Parameters.AddWithValue("@dtPhone", dtPhone)
  32.                 adapter.UpdateCommand.Parameters.AddWithValue("@dtEmail", dtEmail)
  33.                 adapter.UpdateCommand.Parameters.AddWithValue("@dtimage", dtimage)
  34.                 adapter.UpdateCommand.ExecuteNonQuery()
  35.             Next
while executing i am getting error in this line :**adapter.UpdateCommand.ExecuteNonQuery()**
Error:`No mapping exists from object type System.Drawing.Bitmap to a known managed provider native type`
so i made small change in my code ..change is
instead of this line '**adapter.UpdateCommand.Parameters.AddWithValue(" @dtimage", dtimage)**' i added code like this

Expand|Select|Wrap|Line Numbers
  1. Dim md As New MemoryStream()
  2.                 dtimage.Save(md, System.Drawing.Imaging.ImageFormat.Gif)
  3.                 Dim imagedata As Byte() = md.ToArray()
  4.      adapter.UpdateCommand.Parameters.AddWithValue("@dtimage", imagedata )
after adding this code am not getting any error..but not saving my image..that saving some another thing..what is wrong with my code
Jan 22 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.