943,706 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 4369
  • VB.NET RSS
Nov 28th, 2008
0

Re: upload images and store the location in a database

Expand Post »
Click to Expand / Collapse  Quote originally posted by quansah ...
i want to upload files into a folder and store the relative loaction of that file in a database using php and mysql. help
how to upload image in vb.net.i need coding so please somebudy help me.

thank you
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
venkat554 is offline Offline
2 posts
since Nov 2008
Nov 28th, 2008
0

Re: upload image in vb.net

Post moved to BV.NET section
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,655 posts
since Dec 2004
Nov 28th, 2008
0

Re: upload image in vb.net

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).
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Reputation Points: 10
Solved Threads: 9
Junior Poster
sierrainfo is offline Offline
144 posts
since May 2008
Dec 4th, 2008
0

Re: upload images and store the location in a database

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()
Reputation Points: 10
Solved Threads: 0
Newbie Poster
venkat554 is offline Offline
2 posts
since Nov 2008
Dec 4th, 2008
0

Re: upload image in vb.net

That works. If you have an existing row to update. If you want to insert a new one, the code changes a bit:
VB.NET Syntax (Toggle Plain Text)
  1. 16. Dim command As New SqlCommand("INSERT INTO MyTable (Picture) VALUES (@Picture); SELECT @@IDENTITY AS 'Identity'", connection)
  2. 17. Dim ThisPictureID As Integer
  3. 26. ThisPictureID = CInt(command.ExecuteScalar())
Now ThisPictureID contains new ID.
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Email in vb.net
Next Thread in VB.NET Forum Timeline: How to insert,retrieve and update pictures with other data's[VB.Net] in SQL Server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC