473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

load image from mssql database

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
0 1193

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

Similar topics

1
by: Manuel | last post by:
Hello, I try to export a mssql database into a csv-file. I tried this with asp, but it doesn't work. <% Dim objConn Dim csv_path
0
by: Rookie Card | last post by:
Issue - Reformating the Dates in ASP.NET from a MSSQL Database that has <NULL> values in a SmallDateTime Field to read "Dec 8, 2000" instead of "12/8/2000 12:00:00 AM" (As you might already...
2
by: Beruang | last post by:
Hi, How to load image from database MS SQL Server into PictureBox if I have Table called Student(StudID, Name, StudImage) StudImage data types is Image. Thanks
0
by: Nicolas | last post by:
please how to synchronise mssql database from db2/400 ? I whish I have my db2/400 database as master and replicate it in an mssql server 2005 for reading thanks Nicolas
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
9
by: Advo | last post by:
Im having major problems trying to connect to a mssql database thats hosted on our server. I've got the ip, username, password and database name, yet no matter what i try, I cant seem to...
3
bhing
by: bhing | last post by:
Ciao!!.. I am currently working with mysql database now and i am trying to get some fields in the mssql database.table.. I want to automatically add those fields to my mysql database table, or if...
0
by: anjali123 | last post by:
Hi, I want to prepare crystal reports for my project. I am using the database that is inbuilt with the visual studio (MSSql Database file). I didnt know what to choose as datasource to create a...
0
by: alibaba1 | last post by:
Hey Everyone hope all ok. I am needing your expertise. I have an html form and inside of it i have a drop down option to choose a state <select name="State"> <option value="0"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.