when uploading it you are presumably storing them in a predefined folder and therefore simply store the path relative to the root in the db with the file name or alternatively if they are all in a single location then there is only a need to store the filename as the path will be the same in all cases.
storing path into the database is pretty easy task. You store the path as any other string value. Your database field should be varchar(xx) for MSSQL or text datatype if you are using MSAccess as backend. means INSERT INTO table1 (Path) VALUES ('" & txtImagePath.Text & "') would be just fine ... assuming that txtImagePath holds the path value. Also displaying an image according the path stored into db is very simple: Dim thePath as String strSQL = "SELECT Path FROM Table1 WHERE ..." {...} thePath = commandobject.ExecuteScalar() 'show the image inside the pictureBox Me.PictureBox.Image = Image.FromFile(thePath) Code (markup): HTH Regards p.s. please notice that this is VB.NET code so if you need C# version i would be glad to provide you the C# code too.
Btw, i forgot to mention that you can also store the image entirely too. You can store the file as Binary large object (BLOB) storage in database. For example: Private Sub File2OleDbBlob(ByVal SourceFilePath As String) Try oledbcon.Open() strSQL = "INSERT INTO Users (UserPhoto) VALUES(@BLOBData)" Dim fs As New System.IO.FileStream(SourceFilePath, IO.FileMode.Open, IO.FileAccess.Read) Dim b(fs.Length() - 1) As Byte fs.Read(b, 0, b.Length) fs.Close() cmd = New OleDbCommand(strSQL, oledbcon) Dim P As New OleDbParameter("@BLOBData", OleDbType.LongVarBinary, b.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, b) cmd.Parameters.Add(P) cmd.ExecuteNonQuery() Catch ex As Exception MsgBox(ex.Message) Finally oledbcon.Close() End Try End Sub Code (markup): It's very easy to read the image back and display in the pictureBox too ... but as you probably don't need this way i will avoid to show you how. Regards
To insert into a blob, you need to convert to byte array (as in byte()). I also advise doing it via Stored PRoc
Ccoonen, Actually I don't see any difference if you do that via SP's ... the issue about Inserting BLOB data is that in this way you can dramatically increase the size of your database. You're better off storing the path(s) to the DB. Regards