用DELPHI通过DBEngine创建动态创建ACCESS问题。为什么它总是说我没有注册类别!!!!!!!!(40分)

  • 主题发起人 主题发起人 delphilove
  • 开始时间 开始时间
D

delphilove

Unregistered / Unconfirmed
GUEST, unregistred user!
我是按照此方法创建的
在引用部分加入:

uses DAO97;

实现部分:

procedure TFormOffice.BitBtn4Click(Sender: TObject);

var

Engine:DBEngine;

begin

Engine:=CoDBEngine.Create;

Engine.CreateDatabase('c:/NewAccess.mdb',';LANGID=0x0804;CP=936;COUNTRY=0;',dbEncrypt);

end;
 
ODBC建立Access文件
先声明:
function SQLConfigDataSource(hwnd:HWND;fRequest:WORD;lpszDriver:String;lpszAttributes:String):boolean;stdcall;external 'ODBCCP32.dll';

const ODBC_ADD_DSN = 1;
var
sWrkStr:String;
FileName:String;

FileName:='aa.mdb';
sWrkStr := 'CREATE_DB="' + FileName + '";' ;
SQLConfigDataSource(0,ODBC_ADD_DSN,'Microsoft access Driver (*.mdb)',PChar(sWrkStr));
 
使用AdoX建立MDB数据库
procedure CreateNewDatabase(DatabaseFileName: string);
var
cat: OleVariant;
begin
if FileExists(DatabaseFileName) then
begin
if MessageBox(Application.Handle, PChar('Database ' + DatabaseFileName + ' has existed!' + #13#10
+ 'Delete this database and create a new database ?'), 'Database Exists',
MB_YESNO + MB_ICONWARNING + MB_DEFBUTTON2) = mrNo then
exit;
if not DeleteFile(DatabaseFileName) then
begin
MessageBox(Application.Handle,
PChar('Cannot delete database ' + DatabaseFileName),
'Delete Database Error!', MB_OK + MB_ICONERROR);
exit;
end;
end;
cat := CreateOleObject('ADOX.Catalog');
cat.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + DatabaseFileName);
if ConnectDatabase(DatabaseFileName) then
begin
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create Table FaqClass ' +
'(' +
'ClassID INT not null,' +
'ClassTitle char(100) not null,' +
'ParentClassID INT not null,' +
'ClassType TINYINT DEFAULT 0' +
')';
adoquryClass.ExecSQL;
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create UNIQUE Index ClassIDIndex ON FaqClass (ClassID)';
adoquryClass.ExecSQL;
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create Index ClassTitleIndex ON FaqClass (ClassTitle)';
adoquryClass.ExecSQL;
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create Index ParentClassIDIndex ON FaqClass (ParentClassID)';
adoquryClass.ExecSQL;
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create Index ClassTypeIndex ON FaqClass (ClassType)';
adoquryClass.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Table FaqMemo' +
'(' +
'MemoID INT not null,' +
'ParentClassID INT not null,' +
'MemoTitle char(100) not null,' +
'MemoText TEXT,' +
'MemoPublic BIT DEFAULT 0,' + //缺省是不公开
'MemoLastModifyTime DATETIME' +
')';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create UNIQUE Index MemoIDIndex ON FaqMemo (MemoID)';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Index ParentClassIDIndex ON FaqMemo (ParentClassID)';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Index MemoTitleIndex ON FaqMemo (MemoTitle)';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Index MemoPublicIndex ON FaqMemo (MemoPublic)';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Index MemoLastModifyTimeIndex ON FaqMemo (MemoLastModifyTime)';
adoquryMemo.ExecSQL;
end;
end;
 
你写的出错,估计应该是DAO版本问题。
 
接受答案了.
 
后退
顶部