| | |
upload image in vb.net
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
Post moved to BV.NET section
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Dealing with images and databases is basically done with byte arrays.
Here's a one starting point with VB.NET code samples from my blog:
Convert image to byte array and vice versa
Save binary data to SQL Server with VB.NET
You may also try Daniweb's site search. I've answered the same or at least very similar question few times. A pretty good search phrase is "image SQL Server VB.NET" (without quotes).
Here's a one starting point with VB.NET code samples from my blog:
Convert image to byte array and vice versa
Save binary data to SQL Server with VB.NET
You may also try Daniweb's site search. I've answered the same or at least very similar question few times. A pretty good search phrase is "image SQL Server VB.NET" (without quotes).
Teme64 @ Windows Developer Blog
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
15. Dim connection As New SqlConnection("connection string here")
16. Dim command As New SqlCommand("UPDATE MyTable SET Picture = @Picture WHERE ID = 1", connection)
17.
18. Using picture As Image = Image.FromFile("file path here")
19. Using stream As New IO.MemoryStream
20. picture.Save(stream, Imaging.ImageFormat.Jpeg)
21. command.Parameters.Add("@Picture", SqlDbType.VarBinary).Value = stream.GetBuffer()
22. End Using
23. End Using
24.
25. connection.Open()
26. command.ExecuteNonQuery()
27. connection.Close()
16. Dim command As New SqlCommand("UPDATE MyTable SET Picture = @Picture WHERE ID = 1", connection)
17.
18. Using picture As Image = Image.FromFile("file path here")
19. Using stream As New IO.MemoryStream
20. picture.Save(stream, Imaging.ImageFormat.Jpeg)
21. command.Parameters.Add("@Picture", SqlDbType.VarBinary).Value = stream.GetBuffer()
22. End Using
23. End Using
24.
25. connection.Open()
26. command.ExecuteNonQuery()
27. connection.Close()
That works. If you have an existing row to update. If you want to insert a new one, the code changes a bit: Now ThisPictureID contains new ID.
VB.NET Syntax (Toggle Plain Text)
16. Dim command As New SqlCommand("INSERT INTO MyTable (Picture) VALUES (@Picture); SELECT @@IDENTITY AS 'Identity'", connection) 17. Dim ThisPictureID As Integer 26. ThisPictureID = CInt(command.ExecuteScalar())
Teme64 @ Windows Developer Blog
![]() |
Similar Threads
- Upload image without using fileupload (ASP.NET)
- How To Upload Image In Vb.net (VB.NET)
- Upload a file!!! (VB.NET)
- Preview Upload Image Problem (PHP)
- ImgFree.net - Free Image Host / Photo Albums (Website Reviews)
- Add image uploading to post options (Growing an Online Community)
Other Threads in the VB.NET Forum
- Previous Thread: Email in vb.net
- Next Thread: How to insert,retrieve and update pictures with other data's[VB.Net] in SQL Server
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access account arithmetic array assignment basic box button buttons center check code component connectionstring convert crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist editvb.net excel fade file-dialog firewall folder ftp generatetags hardcopy image images input insert intel isnumericfuntioncall math monitor navigate net networking opacity output passingparameters peertopeervideostreaming picturebox picturebox1 port problem problemwithinstallation project record reports" savedialog searchvb.net select shutdown string survey tcp temp temperature text textbox timer toolbox trim updown user useraccounts usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf






