473,322 Members | 1,755 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,322 software developers and data experts.

Retrieving/Decoding base64 string from database to image and display in image control

Database backend:PostgreSQL
Database Name: MoviesDirectory
Table Name: picture
Column: img DataType:bytea

First, I store my uploaded images which may be either .jpg,.gif,.png with the following codes:
Expand|Select|Wrap|Line Numbers
  1. ....
  2. ....
  3. ....
  4. if (FileUpload1.PostedFile.ContentLength != 0)
  5.             {
  6.                 byte[] b = new byte[FileUpload1.PostedFile.ContentLength];
  7.                 FileUpload1.PostedFile.InputStream.Read(b, 0, b.Length);
  8.                 string basestring = System.Convert.ToBase64String(b, 0, b.Length);
  9.                 TextBox1.Text = basestring;
  10.             }
  11. ....
  12. ...
  13. ...
  14. ConnStr = ConfigurationManager.ConnectionStrings["connect2MD"].ToString();
  15.             Conn = new NpgsqlConnection(ConnStr);
  16.             Conn.Open();
  17.             try
  18.             {
  19.  
  20.                 strSQL = new StringBuilder();
  21.                 strSQL.Append("INSERT INTO picture(img) VALUES (@img)");
  22.                 command = new NpgsqlCommand(strSQL.ToString(), Conn);
  23.  
  24.                 param = new NpgsqlParameter();
  25.                 param.ParameterName = "@img";
  26.                 param.Value = TextBox1.Text;
  27.                 command.Parameters.Add(param);
  28.  
  29.                 command.ExecuteNonQuery();
  30.  
  31.  
  32.             }
  33.             catch (Exception ex)
  34.             {
  35.                 throw (ex);
  36.             }
  37.             finally
  38.             {
  39.                 if (Conn.State == ConnectionState.Open)
  40.                     Conn.Close();
  41.             }
  42. ...
  43. ...
  44. ..
  45.  
The question is that - I want to retrieve back that I have already stored the base64 string and display it with the IMAGE CONTROL on my form.
Nov 11 '10 #1
0 1232

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

Similar topics

5
by: Magnus | last post by:
Hi, I'm programatically posting an image using multipart/form-data. It sends to the server OK, but when I try to view it in the browser, it is still in the base64 string I sent it as:...
2
by: marcelo szwarc via .NET 247 | last post by:
I already broke my head, searched everywhere. PLEASE I NEED YOUR HELP! Do you know how can I convert an image file( like a gif or jpeg ) to a Base64 string? I need to use it to send embedded image...
27
by: gRizwan | last post by:
Hello all, We have a problem on a webpage. That page is sent some email data in base64 format. what we need to do is, decode the base64 data back to original shape and extract attached image...
7
by: Neo Geshel | last post by:
Greetings. I have managed to stitch together an awesome method of posting text along with an image to a database, in a way that allows an unlimited number of previews to ensure that text and...
2
by: Jennyfer Barco | last post by:
Hello, I need to decode a string that is encoded on Base64 format. The string is a GIF image, so it's very long and weird data. Do you have an example on how to do this? Thanks in advance...
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...
7
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed...
1
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for...
10
by: sandeepdhankar10 | last post by:
hi!!! i need some help from the Experts Like u people.. i m creating a applictaion that transfer images to the webservice which store in server memory temp.. and retrive back those images on...
5
by: smclellan86 | last post by:
Hi Everybody, I've been working on this challenge for a while now without much luck. What I'm attempting to do is split a MIME byte response into its individual images. I am given the boundary to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.