Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store an images or documents in the SQL database 1

Status
Not open for further replies.

ayh8disjob

Programmer
May 31, 2001
41
0
0
SG
Does anyone know how to store an images or documents in the SQL database and retreiving it back?

any tutorial or a sample code would be much appreciated.

Thanks in Advance!!!
 

Private Sub SaveToDatabase()
Dim objCnn As ADODB.Connection
Dim objRst As ADODB.Recordset
Dim objStm As ADODB.Stream

Set objCnn = CreateObject("ADODB.Connection")
Set objRst = CreateObject("ADODB.Recordset")
Set objStm = CreateObject("ADODB.Stream")

objCnn.Open "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=mssql2;DATABASE=PUBS;UID=sa;PWD="

objStm.Type = adTypeBinary
objStm.Open
objStm.LoadFromFile "d:\test.gif"

strSQ = "SELECT logo FROM pub_info WHERE pub_id = '0736'"
objRst.Open strSQ, objCnn, 3, 3

objRst("logo") = objStm.Read
objRst.Update
End Sub

Private Sub SaveToFile()
Dim objCnn As ADODB.Connection
Dim objRst As ADODB.Recordset
Dim objStm As ADODB.Stream

Set objCnn = CreateObject("ADODB.Connection")
Set objRst = CreateObject("ADODB.Recordset")
Set objStm = CreateObject("ADODB.Stream")

objCnn.Open "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=mssql2;DATABASE=PUBS;UID=sa;PWD="

strSQ = "SELECT logo FROM pub_info WHERE pub_id = '0736'"
objRst.Open strSQ, objCnn, 3, 1

objStm.Type = 1
objStm.Open

objStm.Write objRst("logo")

objStm.SaveToFile "d:\test.gif", adSaveCreateOverWrite
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top