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

load image from mssql database

P: 1
I have saved a picture as binary data from android studio in MS SQL database. The code to insert the data are given below
Expand|Select|Wrap|Line Numbers
  1.  Bitmap photo = (Bitmap) data.getExtras().get("data");
  2.  
  3.  imageView.setImageBitmap(photo);
  4.  
  5.  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  6.  photo.compress(Bitmap.CompressFormat.PNG , 100, stream);
  7.  byte[] byteArray = stream.toByteArray();
  8.  
  9.  Now I want to retrieve this back but in vb.net. Please help me how I will code this. I have tried the following code but it shows error.
  10.  objcommand = New SqlCommand("select picture from android_data where serial=23", objConnection)
  11.  'Dim dr As SqlDataReader
  12.  'dr = objcommand.ExecuteReader();
  13.  Dim dr As SqlDataReader = objcommand.ExecuteReader()
  14.  If dr.HasRows Then
  15.  dr.Read()
  16.  ' Dim data As Byte() = DirectCast(dr("picture"), Byte())
  17.  
  18.  Dim mybytearray As Byte() = DirectCast(dr("picture"), Byte()) 'this should contain your data
  19.  
  20.  Dim myimage As Image
  21.  Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(mybytearray)
  22.  myimage = System.Drawing.Image.FromStream(ms)
  23.  
  24.  
  25.  ' Dim ms As New MemoryStream(data)
  26.  ' Dim mimage As Image = Image.FromStream(data)
  27.  ' MDIParent1.ButtonItem49.Image = mimage
  28.  PictureBox1.Image = Image.FromStream(myimage).
  29.   End If
Oct 22 '15 #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.