Results 1 to 4 of 4

Thread: Please Help

  1. #1
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250

    Unanswered: Please Help

    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 advance
    Cheers....

    baburajv

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Sure.

    Don't.

    Store the filepaths of the images.
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Aug 2003
    Location
    Kingston, Ontario
    Posts
    106
    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

    Code:
    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...

    Code:
    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.

  4. #4
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250

    :-)

    thank you very much...
    Cheers....

    baburajv

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •