i want opposite of this

Please support our ASP.NET advertiser: 50% off 6 Months Dedicated Server Hosting from 1&1!
Closed Thread

Join Date: Aug 2009
Posts: 85
Reputation: coollife has a little shameless behaviour in the past 
Solved Threads: 0
coollife coollife is offline Offline
Junior Poster in Training

i want opposite of this

 
-1
  #1
Aug 5th, 2009
Hi here image is getting converted into binary and getting inserted into sqltable .

Now I want the opposite of it i mean i want to retrieve the binary
data and display it as image.



  1. protected void btnupload_Click(object sender, EventArgs e)
  2. {
  3.  
  4. // set temporary variable for database connection
  5. SqlConnection SqlCon = new SqlConnection("Data Source=localhost;Initial Catalog=ArjunPlastic;Uid=sa;Pwd=vagi0903");
  6. SqlCon.Open();
  7.  
  8. string SQL = "INSERT INTO pictures (Filename,Picture) VALUES ('flower',@image)";
  9. SqlCommand SqlComm = new SqlCommand(SQL,SqlCon);
  10.  
  11. SqlParameter parimage= new SqlParameter("@image", SqlDbType.Image);
  12.  
  13. // convert image file to byte array and pass to sql parameter value
  14. parimage.Value = FileToByteArray("C:\\Documents and Settings\\Administrator\\Desktop\\4014_thumb.jpg");
  15. SqlComm.Parameters.Add(parimage);
  16. SqlComm.ExecuteNonQuery();
  17.  
  18. }
  19.  
  20. public byte[] FileToByteArray(string FileName)
  21. {
  22. byte[] Buffer = null;
  23.  
  24. // Open file for reading
  25. FileStream FileStream = new FileStream(FileName,FileMode.Open,FileAccess.Read);
  26.  
  27. // attach filestream to binary reader
  28. BinaryReader BinaryReader = new BinaryReader(FileStream);
  29.  
  30. // get total byte length of the file
  31. long TotalBytes = new FileInfo(FileName).Length;
  32.  
  33. // read entire file into buffer
  34. Buffer = BinaryReader.ReadBytes((Int32)TotalBytes);
  35.  
  36. // close file reader
  37. FileStream.Close();
  38. FileStream.Dispose();
  39. BinaryReader.Close();
  40. return Buffer;
  41. }
Last edited by peter_budo; Aug 5th, 2009 at 2:15 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Quick reply to this message  
Join Date: Feb 2009
Posts: 3,793
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 698
Sponsor
Featured Poster
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: i want opposite of this

 
0
  #2
Aug 5th, 2009
Please use code tags when posting code on daniweb:

[code=c#]
...code here...
[/code]


Next -- Please stop opening duplicate thread. I have already given you the answer to that in http://www.daniweb.com/forums/thread209172.html

For some reason you have in your head that I am not storing the image as binary on the SQL server which is not the case. Please try the code first.
Scott Knake
Custom Software Development
Apex Software, Inc.
Quick reply to this message  
Join Date: Dec 2004
Posts: 4,536
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 524
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: i want opposite of this

 
-1
  #3
Aug 5th, 2009
Thread closed, double posting is not welcome.
Stick to original post.
Last edited by peter_budo; Aug 5th, 2009 at 2:17 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum


Views: 295 | Replies: 2
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC