VB.Net Saving\Retrieving image

prabhuforum

New member
Joined
Mar 30, 2007
Messages
1
Programming Experience
1-3
Hi Guys,

I am in need of help from you people
I am facing problem in retrieving image from database.

Problem
I have sql database 2000

I have one table...
It has one column named IMAGE type image 16

Iam using VB.Net
IN my form, I have a picturebox.
I drag the image and placed the image and i saved the image in the database
It got save in binary.. ..byte Array i suppose.

This is code for Saving data
VB.NET:
ostrUpdate.Append("',IMAGE ='")
'ostrUpdate.Append(Me.pbEmp.Image)
Dim ms AsNew System.IO.MemoryStream
Dim im As Image
im = pbEmp.Image
im.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim b(ms.Length - 1) AsByte
ms.Position = 0
ms.Read(b, 0, ms.Length)
ostrUpdate.Append(b)
ostrUpdate.Append("'")
ostrUpdate.Append(" WHERE ")
ostrUpdate.Append(" EMP_NO ='")
ostrUpdate.Append(Me.txtEmpNo.Text.Trim)
ostrUpdate.Append("'")
Return ostrUpdate.ToString
Then i execute the query..it got saved

The real problem is while retrieving..
I bound the entire dataset of my table to a datagrid...
In the datagrid..last column is IMAGE..showing ..byte Array[] ..ok

When i select a row in the datagrid..iam displaying all information in the screen below the datagrid.

My code for that..
VB.NET:
dsAssoc is a datarow...
drAssoc = dsAssociates.Tables(0).RowsdgAssociates.CurrentCell.RowNumber)
Now with this iam displaying all the data from selected row..

My problem
While trying to display the image to the picture box...
It is giving error...

my code:
VB.NET:
pbEmp is my picture box
 
IfNot IsDBNull(drAssoc("IMAGE")) Then
Dim b() As Byte
b = drAssoc("IMAGE")
Dim pic() As Byte = CType(drAssoc.Item("IMAGE"), Byte())
Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(pic)
pbEmp.Image = Image.FromStream(ms)
End if

It is giving error in the line
pbEmp.Image = Image.FromStream(ms)
Invalid parameter is used..

Please let me know the solution for this problem i need immediate reply plssssssssss

 
Last edited by a moderator:
I'm reasonably sure that whacking a load of binary data into a string thus:

VB.NET:
UPDATE emp SET image = '
[FONT=Courier New][COLOR=darkolivegreen]GIF89a&A ÷  ÚY:u£Ü¦¹æl®äÑäóªÑíê—‰³ãŠ½ëËâòr²åöÅ[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]¸ÝaA„¦Õ±Ô턱ã£ÍìäuS’ÃéúÚÒ“ªâÂÝð‚­âh°ä[/COLOR][/FONT][FONT=Courier New][COLOR=darkolivegreen]æzYó·[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]§âmKâëõ¥á«ËìkŠÛd…Ù‹Á遛Þã{jçˆzÔB-œÉëôøýyµæò™y[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]ºÚï¹Òí¢Åê™ÄêJ|½t‘Üÿÿÿæñù~¨äe‘ÌÑ;&š½åþõò•ºåò÷ü|[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]¸çÖI1ËÝòùÓÊ–Èõºçd›ÜêƒbØäó³Î섽蒻èì“yüâÛýéãT‘[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]Úæ½ÜðT„ÂNÙl¡ÞÁÔíp®ä=r´¦Öýy•Ýu«äY•ÛéñùÔèôy©[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]äkšÔíôúÄÙïãí÷˜©×ìŒl÷ÌÁ–™¾éýíèsšËÅàñz©àØêõàfE¨Ä[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]æ~®áüæशßÒÝñ¶åÿ‚—ÍÞgT|˜ÞþñîÞíö°Ôöô¾±ãpN¹Ìê[‰ÿ[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]úø8n²QŒÙ¶×îP€¿ižÝÞéö^ŒÊò¬–Ýíùìñù󳞐¶ãˆœ[/COLOR][/FONT][FONT=Courier New][COLOR=darkolivegreen]ÐÙëóùü[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]ÿ£Ìôœ±ã¨Æ鄴篿捷æãï÷}ªàÉÛð´ÄêÊãûÚZHÂÎìÿýüÔíÿ[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]ËÔë]™Üo×Gyº®äÀ×ïoŽÛž¿æw¦ÞaÈ•Çê»Õðßm[,f¬ç|\s[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]§ß?t¶ð¤y®åþ÷õÕáñt®ä÷úýájHüýþýþÿBu·ñ®¢ëÜé[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]ó[/COLOR][/FONT][FONT=Courier New][COLOR=darkolivegreen]êôùîöûÁáüåwVX†ÅÞôÿÐÙï~£Ò­Èè[¢î¡Še”Ïæb鏂[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]èò÷»ß[/COLOR][/FONT][FONT=Courier New][COLOR=darkolivegreen]ý~¨ÛÊÕð1j¯t·æ¯Ù±ÊçéïùÛìõi–Ð{¬áäoÿûú[/COLOR][/FONT][FONT=Courier New][COLOR=darkolivegreen]é€_ê[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]îöM~[/COLOR][/FONT][FONT=Courier New][COLOR=darkolivegreen]¿ÏúÀÜ÷¿ËéMÙÌíÿàæôyŸÎÜ^>Àêÿ¸ÇêãvZx§ßéa§¯à[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]ÿÓæøðùÿðv©ß·Ääéôþëˆg³×îáscUž†šÏ­×úN€Àg‡Ú[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]‡¡àÿþþˆ¸é_—Ûr¡ØO¿p£Þ„žß‘ÁðÙçõØQ6îp𱧦ÇëbƒÙ![/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]ù     ,    &A  ÿ ÿ H° Àá)ôà'¥H”ø¦¢Å7!2jÜxq¢G‰[/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]]8äÄP!<„"\ÉreÊ—0cÊœI³¦Í›8sêÜÉså†)VܨŸÑ£øâ)]ï([/COLOR][/FONT]
[FONT=Courier New][COLOR=darkolivegreen]Q¢¥@tXò䇂>MjU蒧ׯ`ÊK6fBx@]P[/COLOR][COLOR=black]'[/COLOR][/FONT]
WHERE emp.id = 123

Is NOT the way you would save binary data to a database. Why dont you try reading a tutorial on How To Read and Write BLOBs In <insert name of your DB here>?
 

Latest posts

Back
Top