import image to db

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Jul 2008
Posts: 7
Reputation: karabela is an unknown quantity at this point 
Solved Threads: 0
karabela's Avatar
karabela karabela is offline Offline
Newbie Poster

import image to db

 
0
  #1
Aug 4th, 2008
i created a sql database with table land.
columns;

LandID int PK
LandCodeID int
LandName nvarchar(100)
LandFlag image Allow Nulls

ive created a dataset in my solution.

from my Data Sources i can drag & drop the table Land to my Form1 as DataGridView. it puts all the columns above on my form. im able to update/add/delete Lands except the flag. i want to double click on the landFlagPictureBox so i can select the jpg image to save it in my database. can anyone help me out?

thanx in advance
Last edited by karabela; Aug 4th, 2008 at 1:07 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 7
Reputation: karabela is an unknown quantity at this point 
Solved Threads: 0
karabela's Avatar
karabela karabela is offline Offline
Newbie Poster

Re: import image to db

 
0
  #2
Aug 6th, 2008
can anyone give me a good direction. i did a lot of google search. but cant find something usefull.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 37
Reputation: ramiljoaquin is an unknown quantity at this point 
Solved Threads: 2
ramiljoaquin ramiljoaquin is offline Offline
Light Poster

Re: import image to db

 
0
  #3
Aug 8th, 2008
Hey, try this one, I just learn if from http://www.codeproject.com/KB/cs/upl..._DataBase.aspx


  1. Stream streamImage=file1.PostedFile.InputStream;
  2.  
  3. int imageLenght=file1.PostedFile.ContentLength;
  4.  
  5. string strType=file1.PostedFile.ContentType;
  6.  
  7. string strType1=file1.Type;
  8.  
  9. string strName=txtName.Text;
  10.  
  11. Byte[] imgData = new byte[imageLenght];
  12.  
  13. int n = streamImage.Read(imgData,0,imageLenght);
  14.  
  15. int result = saveImage(strName,imgData,strType);
  16.  
  17.  
  18. private int saveImage(string strName,byte[] imgData,string strType)
  19.  
  20. { int return1=0;
  21.  
  22. try
  23.  
  24. {
  25.  
  26.  
  27.  
  28. SqlCommand cmd= new SqlCommand("INSERT INTO image1(id,imageLenght,imgtype,bytles) values (@id,@imageLenght,@imgtype,@bytles)", con);
  29.  
  30. cmd.Parameters.Add("@id", SqlDbType.VarChar).Value = strName;
  31.  
  32. cmd.Parameters.Add("@imageLenght", SqlDbType.BigInt).Value = imgData.Length;
  33.  
  34. cmd.Parameters.Add("@imgtype", SqlDbType.VarChar,6).Value= strType;
  35.  
  36. cmd.Parameters.Add("@bytles", SqlDbType.Image).Value = imgData;
  37.  
  38. con.Open();
  39.  
  40. return1 = cmd.ExecuteNonQuery();
  41.  
  42. con.Close();
  43.  
  44. }
  45.  
  46. catch(Exception ex)
  47. {
  48. Response.Write(ex.Message);
  49. }
  50.  
  51.  
  52.  
  53. return return 1;
  54.  
  55. }
  56. finally
  57. {
  58. con.Close();
  59. }
Last edited by Tekmaven; Aug 8th, 2008 at 4:43 pm. Reason: Code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 39
Reputation: nvmobius is an unknown quantity at this point 
Solved Threads: 4
nvmobius nvmobius is offline Offline
Light Poster

Re: import image to db

 
0
  #4
Aug 8th, 2008
You'll have to trust me on this, but you really DO NOT WANT to store the image in your database. Instead store a file path or Uri to the image in your database and read it from disk when you want to display it.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC