Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Image Data and ADO
Message
De
29/06/2001 06:03:12
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Titre:
Image Data and ADO
Divers
Thread ID:
00525079
Message ID:
00525079
Vues:
48
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
**Save to db

	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  	   &&Open Static Client default 0
		.LockType = 4		  &&Lock Batch Optistic  default 1
		.CursorLocation = 3   &&Client Side Cursor  default 2
		.Open
	endwith
	orecordset.AddNew
	orecordset.Fields("OLEID").value="12345"
	orecordset.Fields("OLETYPE").value="BMP"
	orecordset.Fields("OLEOBJ").appendchunk(FILETOSTR(GETFILE()))
	orecordset.updatebatch


*Get from db


 oConnection = CreateObject("adodb.connection")
	with oConnection
		.Provider = "SQLOLEDB.1"
		.ConnectionString = "Persist Security Info=False;Password=quest;User ID=quest;Data Source=TJM"
		.Open
	endwith
	
*!* Creates the RS
	oRecordSet = CreateObject("adodb.recordset")
	with oRecordSet 
		.ActiveConnection = oConnection
		.Source = "Select * From oleobjs"
		.CursorType = 3  	   &&Open Static Client default 0
		.LockType = 3		  &&Lock Batch Optistic  default 1
		.CursorLocation = 3   &&Client Side Cursor  default 2
		.Open
	endwith

	oADOStream = CREATEOBJECT("ADODB.Stream")
	oADOStream.TYPE = 1	&& 1=Binary Data, 2=Text Data.
	oADOStream.OPEN

	oADOStream.WRITE(oRecordSet.FIELDS("oleobj")) 	&& Pass data to the stream object.
	lcImageName = "c:\fromdb."+oRecordset.fields("oletype").value
	oADOStream.SaveToFile(lcImageName,2)         	&& Saves stream object to a file.
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...
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform