简体   繁体   English

如何从数据库中读取CLongBinary字段并将其写入CFile对象?

[英]How can I read a CLongBinary field from my database and write it into a CFile object?

im using a CRecordset to get data from my SQL Server. 即时通讯使用CRecordset从我的SQL Server获取数据。 One table stores a binary file (pdf, odt, ...). 一个表存储一个二进制文件(pdf,odt等)。 My VisualStudio maps the columns to a CLongBinary field. 我的VisualStudio将列映射到CLongBinary字段。

How can I read and open the file from the CLongBinary field? 如何从CLongBinary字段读取和打开文件?

im using some ancient version 4.2 of MFC, VisualStudio 6.0 即时通讯使用的是MFC, VisualStudio 6.0的某些较早版本4.2

Do something like this. 做这样的事情。 This will just give you an idea. 这只会给您一个想法。 I haven't tested the code. 我还没有测试代码。

CLongBinary myfield ;

... retrive myfield from database here


BYTE *dataptr = (BYTE*)GlobalLock(myfield.m_hData) ;

// now dataptr points to your raw data, and myfield.m_dwDataLength is the length of that data

CString tempname = ... create temporary filename somewhere
CFile myfile ;
myfile.Open(tempfilename, CFile::modeCreate|CFile::modeWrite);
myfile.Write(dataptr, myfield.m_dwDataLength) ,
myfile.Close() ;
GlobalUnlock(myfield.m_hData) ;

ShellExecute(NULL, _T("open"), tempfilename, NULL, NULL, SW_SHOW) ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM