access数据库 存储 txt文件
如题,我想将txt文件存入access数据库,用到的时候能够提取出来,不能改变里面的格式,请问有什么好的方法吗?
[解决办法]
就跟存图片的操作一样的,字段类型用ole对象,给你一段例子代码
TMemoryStream *Temp = new TMemoryStream();
Temp->LoadFromFile("1.txt");
ADOQuery1->Active = false;
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("update test set byte1 = :BYTEE where name = 'test'");
ADOQuery1->Parameters->Items[0]->LoadFromStream(Temp,ftBlob);
ADOQuery1->ExecSQL() ;
delete Temp;
//读的时候
ADOQuery1->Active = false;
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("select byte1 from test where name = 'test'");
ADOQuery1->Open() ;
TBlobField * pField1=(TBlobField *)ADOQuery1->FieldByName("byte1");
if(!pField1->IsNull)
{
TADOBlobStream* pmem=new TADOBlobStream (pField1,bmRead);
pmem->Seek(0,soFromBeginning);
TMemoryStream *Temp1 = new TMemoryStream();
Temp1->LoadFromStream(pmem);
Temp1->SaveToFile("1.txt");
delete Temp1,pmem;
}