HI,
Kindly Guide me how to store picture files in SQL server 2000 using Visual studio 2005
In your database design, make space for a field of type text.
When you work with the images, serialize them into a string and insert the string into the DB. When you retrieve the string, you have to convert it from string to an image.
Have a look at those two methods:
public static string ImageToString(System.Drawing.Image img) { MemoryStream ms =new MemoryStream(); img.Save(ms, img.RawFormat);byte[] array = ms.ToArray();return Convert.ToBase64String(array); }public static System.Drawing.Image StringToImage(string imageString) {if (imageString ==null)throw new ArgumentNullException("imageString");byte[] array = Convert.FromBase64String(imageString); System.Drawing.Image img = System.Drawing.Image.FromStream(new MemoryStream(array));return img; }
|||
Public Shared Function ImageToString(ByVal imgAs System.Drawing.Image)As String Dim msAs MemoryStream =New MemoryStream() img.Save(ms, img.RawFormat)Dim array()As Byte = ms.ToArray()Return Convert.ToBase64String(array)End Function Public Shared Function StringToImage(ByVal imageStringAs String)As System.Drawing.ImageIf imageStringIs Nothing Then Throw New ArgumentNullException("imageString")End If Dim array()As Byte = Convert.FromBase64String(imageString)Dim imgAs System.Drawing.Image = System.Drawing.Image.FromStream(New MemoryStream(array))Return imgEnd FunctionIn VB.NET this should do the trick:
I found this language conversion tool, in case you need it for later use:http://www.dotnetspider.com/convert/
Please mark my post as anwer if it solves your issue.
|||Thanks
Reagrds
Fakhruddin
No comments:
Post a Comment