DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   upload image in vb.net (http://www.daniweb.com/forums/thread159832.html)

venkat554 Nov 28th, 2008 3:14 am
Re: upload images and store the location in a database
 
Quote:

Originally Posted by quansah (Post 202627)
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

peter_budo Nov 28th, 2008 7:12 am
Re: upload image in vb.net
 
Post moved to BV.NET section

Teme64 Nov 28th, 2008 8:44 am
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).

sierrainfo Dec 3rd, 2008 6:58 am
Re: upload image in vb.net
 
Hope it will help u.

http://www.aspnettutorials.com/tutor...g-ToDB-VB.aspx

http://forums.asp.net/p/739822/996518.aspx

venkat554 Dec 4th, 2008 7:23 am
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()

Teme64 Dec 4th, 2008 9:28 am
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:
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())
Now ThisPictureID contains new ID.


All times are GMT -4. The time now is 11:53 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC