I have read through all the past posts and have tried to do this in many ways.
None seem to work.
I need to read and write a file to the database using ADO.
Does anyone have code that will do this..
I tried to via the article on MSDN about reading data from a stream but it doesn't work (I placed a file in the DB using a DBC and trie dto read it out with this code and it failed!)
I also tried Vlad's suggestions but haven't got it to work.
I also read that get chunk does not work.
I am not keen on writing a VB DLL (can you pass a connection, I think I read you can't, cause I don't want two connections..)
I am using SQL Server 7 and ADO 2.6 with VFP 7.
My code right now (The saved image is corupt and the fecthed image is also corrupt so neither work!) looks like:
Table is OBLOBJS
OLEID CHAR 5
OLETYPE CHAR 3
OLEOBJ Image
oConnection = CreateObject("adodb.connection")
with oConnection
.Provider = "SQLOLEDB.1"
.ConnectionString = "Persist Security Info=False;Password=quest;User ID=quest;Data Source=TJM"
.Open
endwith
oRecordSet = CreateObject("adodb.recordset")
with oRecordSet
.ActiveConnection = oConnection
.Source = "Select * From oleobjs"
.CursorType = 3
.LockType = 4
.CursorLocation = 3
.Open
endwith
orecordset.AddNew
orecordset.Fields("OLEID").value="12345"
orecordset.Fields("OLETYPE").value="BMP"
orecordset.Fields("OLEOBJ").appendchunk(FILETOSTR(GETFILE()))
orecordset.updatebatch
oConnection = CreateObject("adodb.connection")
with oConnection
.Provider = "SQLOLEDB.1"
.ConnectionString = "Persist Security Info=False;Password=quest;User ID=quest;Data Source=TJM"
.Open
endwith
oRecordSet = CreateObject("adodb.recordset")
with oRecordSet
.ActiveConnection = oConnection
.Source = "Select * From oleobjs"
.CursorType = 3
.LockType = 3
.CursorLocation = 3
.Open
endwith
oADOStream = CREATEOBJECT("ADODB.Stream")
oADOStream.TYPE = 1
oADOStream.OPEN
oADOStream.WRITE(oRecordSet.FIELDS("oleobj"))
lcImageName = "c:\fromdb."+oRecordset.fields("oletype").value
oADOStream.SaveToFile(lcImageName,2)
Unfortunatly giving up is not an option this has to work somehow!
Any help will be greatly appreciated..My prefered method would be using getchunk and appendchunk...