i'd like to get info on storing photos to Sql Server 2000 using VB 6.0. i searched many vb sites, but all have code samples in vb.Net.
can any 1 give code samples if possible?
one more thing..
my application uses mssql server running in an IBM server machine ,i hav plans to give one machine as a back up server. i wud like to have the data updated on both machines simultaneously..
i.e,
either the data must go to both the Machines (SErver & Back Up Server) or it should not go to both.
how can i implement this?
i do welcome your views/ideas in this context.
thanks in advanceSure.
Don't.
Store the filepaths of the images.|||I'd have to agree with Brett about storing only the path to a file but if you really must store the image in a DB try this...
Include a reference to "Microsoft ActiveX Data Objects 2.5 Library" (or later)
Using the Northwind DB as an example, open your connection and add the following
Dim rs as New ADODB.Recordset
Dim sql as String
Dim mStream as Stream
sql = "SELECT EmployeeID, Photo FROM Employees Where EmployeeID=1"
rs.Open sql, adoConn, adOpenKeyset, adLockPessimistic
' Load the image into the DB field
Set mStream = New ADODB.Stream
mStream.Type = adTypeBinary
mStream.Open
mStream.LoadFromFile "c:\MyNewPhoto.jpg" ' <-******* Your filename here
rs.Fields("Photo").Value = mStream.Read
rs.Close
Set rs = Nothing
That replaces the existing image with a new one. To dump the existing image to a file you can use...
Dim rs as New ADODB.Recordset
Dim sql as String
Dim mStream as Stream
sql = "SELECT * FROM Employees Where EmployeeID=1"
rs.Open sql, adoConn, adOpenKeyset, adLockPessimistic
Set mStream = New ADODB.Stream
mStream.Type = adTypeBinary
mStream.Open
mStream.Write rs.Fields("Photo").Value
mStream.SaveToFile "c:\MyImage.jpg", adSaveCreateOverWrite ' <-******* Your filename here
rs.Close
Set rs = Nothing
The major problem I've found with storing images in the DB is ease of editing. A file can be loaded into Paint or whatever but a DB image must first be dumped to disk and then sent back after editing.|||thank you very much...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment