首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

ado存取文件的有关问题,小弟我新手不太懂

2012-02-14 
ado存取文件的问题,我新手不太懂如图,界面上有TADOConnection(名为con1),TADOQuery(名为qry1),TOpenDialog

ado存取文件的问题,我新手不太懂

如图,界面上有TADOConnection(名为con1),TADOQuery(名为qry1),TOpenDialog(名为dlgOPen),两个按钮(名为btn1,btn2)。
存入按钮打开一个文件对话框,选取一个文件存入数据库(ado)。
代码怎么实现?下面是我写的,但是插入不了文件。

C/C++ code
//---------------------------------------#include <vcl.h>#pragma hdrstop#include "Unit1.h"#include "ComObj.hpp"//---------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TForm1 *Form1;//---------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)    : TForm(Owner){}//---------------------------------------void __fastcall TForm1::FormCreate(TObject *Sender){  AnsiString path=ExtractFilePath(Application->ExeName);  Variant CreateAccess;  AnsiString s;  if(!FileExists(Filename))  {    s="Provider=Microsoft.Jet.OLEDB.4.0;Data source="+path+"test.mdb";    CreateAccess=CreateOleObject("ADOX.Catalog");    CreateAccess.OleFunction("Create",s.c_str());    con1->ConnectionString=s;    qry1->SQL->Add("create table mytable1(id int,\                    nodeid int,itemcaption char(255),\                    content binary,Primary Key(id))");    qry1->ExecSQL();    con1->Close();  }  con1->ConnectionString=s;}//---------------------------------------void __fastcall TForm1::btn1Click(TObject *Sender){    if(!dlgOpen1->Execute())        return;    qry1->Open();    qry1->Edit();    qry1->FieldByName("id")->AsInteger = 1;    qry1->FieldByName("nodeid")->AsInteger = 0;    qry1->FieldByName("itemcaption")->AsString = "我的文档";    TMemoryStream *tmpStream = new TMemoryStream();    TBlobField *tmpField;    tmpStream->LoadFromFile(dlgOpen1->FileName);    tmpField = (TBlobField *)qry1->FieldByName("content");    tmpField->LoadFromStream(tmpStream);    qry1->Post();    tmpField = NULL;    delete tmpStream;}//---------------------------------------


[解决办法]
--#
[解决办法]
字段类型得改
C/C++ code
    qry1->SQL->Add("create table mytable1(id int,\                    nodeid int,itemcaption char(255),\                    content OLEObject,Primary Key(id))"); 

热点排行