var
form2: Tform2;
procedure treeviewshow;
procedure CreateConnection;
implementationuses Unit3, Unit4, Unit5, Unit6, Unit7, Unit8, Unit9, Unit11, Unit23,
login, Unit24, Unit25, Unit26,ComObj; procedure CreateConnection;
var
CreateAccess: OLEVariant;
begin
//建库方法
CreateAccess := CreateOleObject('ADOX.Catalog');
CreateAccess.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\temp.mdb');
CreateAccess := Unassigned; //建表方法
{ADOCommand6.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Password=2008;Data Source=E:\JAVATOOL\hqkcs\hqkc.mdb;Persist Security Info=True';
ADOCommand6.CommandText:='CREATE TABLE Table1(Field1 varchar(10),Field2 varchar(10))';
ADOCommand6.ExecSQL; }
end;
按钮单击事件调用:
procedure Tform2.SpeedButton17Click(Sender: TObject);
begin
CreateConnection ;
//CreateConnection(Format('Provider=Microsoft.Jet.OLEDB.3.51;Data Source=%sTest.mdb',[ExtractFilePath(Application.ExeName)]));
//tree ;
end;
出现错误提示:C:\Documents and Settings\Administrator\桌面
form2: Tform2;
procedure treeviewshow;
procedure CreateConnection;
implementationuses Unit3, Unit4, Unit5, Unit6, Unit7, Unit8, Unit9, Unit11, Unit23,
login, Unit24, Unit25, Unit26,ComObj; procedure CreateConnection;
var
CreateAccess: OLEVariant;
begin
//建库方法
CreateAccess := CreateOleObject('ADOX.Catalog');
CreateAccess.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\temp.mdb');
CreateAccess := Unassigned; //建表方法
{ADOCommand6.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Password=2008;Data Source=E:\JAVATOOL\hqkcs\hqkc.mdb;Persist Security Info=True';
ADOCommand6.CommandText:='CREATE TABLE Table1(Field1 varchar(10),Field2 varchar(10))';
ADOCommand6.ExecSQL; }
end;
按钮单击事件调用:
procedure Tform2.SpeedButton17Click(Sender: TObject);
begin
CreateConnection ;
//CreateConnection(Format('Provider=Microsoft.Jet.OLEDB.3.51;Data Source=%sTest.mdb',[ExtractFilePath(Application.ExeName)]));
//tree ;
end;
出现错误提示:C:\Documents and Settings\Administrator\桌面
project jgbx.exe raised exception class EoleException with message '找不到可安装的 ISAM.',progress stopped use step or run to continue
请各位帮一下,小弟初学,对这一块不太会,尽量详细一些, 感激不尽....
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj, ADODB, DB;type
TForm1 = class(TForm)
Button1: TButton;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure CreateAccess;
function SetMDBConnection(aConnection: TADOConnection; aMdb: string): Boolean;
{ Public declarations }
end;const
Mdb = 'test.mdb';
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
CreateAccess; //创建ACCESS
if SetMDBConnection(ADOConnection1, ExtractFilePath(Application.ExeName) + Mdb) then
ShowMessage('数据库连接成功!')
else
ShowMessage('数据库连接失败!');
end;procedure TForm1.CreateAccess;
var
lCreateAccess: OleVariant;
lMdb: string;
begin
lMdb := ExtractFilePath(Application.ExeName) + mdb;
if FileExists(lMdb) then
DeleteFile(lMdb);
lCreateAccess := CreateOleObject('ADOX.CATALOG');
lCreateAccess.Create('Provider=Microsoft.jet.oledb.4.0;data source=' + lMdb);
end;function TForm1.SetMDBConnection(aConnection: TADOConnection;
aMdb: string): Boolean;
begin aConnection.Close;
aConnection.LoginPrompt := False;
aConnection.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;'
+ 'Data Source=' + aMdb + ';'
+ 'Persist Security Info=False';
try
aConnection.Connected := True;
Result := True;
except
Result := False;
end;
end;end.完整的例子 我试了 可以的
function TForm1.SetMDBConnection(aConnection:TADOConnection;aMdb:string):Boolean;
begin
aConnection.Close;
aConnection.LoginPrompt:=False;
aConnection.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'+'Data Source='+aMdb+';'+'Persist Security Info=False';
try
aConnection.Connected:=True;
showmessage('ssss');
// CreateTableQuery.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'+'Data Source='+aMdb+';'+'Persist Security Info=False'; CreateTableQuery.close;
CreateTableQuery.Sql.Clear;
// CreateTableQuery.SQL.Text:='CREATE TABLE Table1(Field1 varchar(10),Field2 varchar(10))';
CreateTableQuery.SQL.Text:='CREATE TABLE B01(B0110 varchar(30),'+
'B0105 varchar(120),createusername datetime,CreateTime datetime,'+
'ModUserName varchar(50),ModTime datetime,D0101 int,D0102 int,D0103 int,D0104 int,'+
'D0105 int,D0106 int,D0107 int,D0108 int,D0109 int,D010A int,D010B int,D010C int,'+
'D010D int,D010E int,D010F int,D010G int,D010H int,D010I int,D010J int,D010K int,'+
'D010L int,D010M int,D010N int,D010O int,D010P int,D010Q int,D010R int,'+
'B0160 varchar(50),B0150 varchar(50),D010S datetime,D010T varchar(50),'+
'D010U int,D010V int,D010W text)';
CreateTableQuery.ExecSQL; //备注
//CreateTableQuery.close;
CreateTableQuery.Sql.Clear;
CreateTableQuery.SQL.add('insert into OPENROWSET(''Microsoft.Jet.OLEDB.4.0'','''+aMdb+''';''Admin'';'''';B01)');
CreateTableQuery.SQL.add('select * from Ykchr.dbo.B01');
// CreateTableQuery.open;
CreateTableQuery.ExecSQL;
//备注 Result:=True;
except
Result:=False;
end;
end;
如果不加两个备注之间的这一句插入语句是可以运行的,但如果加了这一句就提示下面这一句语法错误:
project project1.ext raised exception class EOLeException with message'INSERT INTO'语句的语法错误。'.
process stopped Use Step or run to continue.不知道这一句插入语句应该怎么写,请赐教?