如何用delphi创建accsse的一个表(200)(200分)

F

fox007

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个accsse的数据库,里面有几个表,现在需要用delphi在程序中创建一个
自定义的表!
 
采用ADOX Object Model比较简单点,也可以通过其它控件生成表,然后生成字段,或者通过
SQL语句执行操作生成一张表
 
用SQL语句,例如:
AA.SQL.Clear;
AA.SQL.Add('CREATE TABLE ABC(A1 IDENTITY(1,1) PRIMARY KEY,A2 VARCHAR(10) NOT NULL )');
AA.ExecSQL
 
迟了。
同意楼上。
 
应该先查一下问题,然后再问,这个问题好像已经有很多人问过了.[:)][:)][:)]
 
Access 中的自增变量是
autoincrement型
 
在dephi帮助中找creattable。
 
你必须通过ODBC接口,然后就用Create语句
 
sql create table就行了呀
 
创建access数据库和表:
uses comobj;

procedure Tform1.CreateDb(DbName: string);
var
Dbnew:OleVariant;
begin
if FileExists(DbName) then
begin
if MessageBox(Application.Handle,PChar('数据库 '
+ DbName + ' 已存在!'+ #13#10 +'是否覆盖?'),
'警告',MB_YESNO + MB_ICONWARNING) = idNo then exit;
if not DeleteFile(DbName) then
begin
MessageBox(Application.Handle,
PChar('不能删除数据库:' + DbName),
'错误',MB_OK + MB_ICONERROR);
exit;
end;
end;

dbnew:=CreateOleObject('ADOX.Catalog');
dbnew.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + DbName);

adoq1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
+dbname+';Persist Security Info=False';
adoq1.Close;
adoq1.SQL.Clear;
adoq1.SQL.add('Create Table 测试2 (ID INT PRIMARY KEY not null,'
+'姓名 char(8) not null,年龄 INT not null)');
adoq1.ExecSQL;
adoq1.Close;
adoq1.SQL.Clear;
adoq1.SQL.add('Create UNIQUE Index IDIndex ON 测试2 (ID)');
adoq1.ExecSQL;
adoq1.Close;
adoq1.SQL.Clear;
adoq1.SQL.add('Create Index xmIndex ON 测试2 (姓名)');
adoq1.ExecSQL;
adoq1.Close;
adoq1.SQL.Clear;
adoq1.SQL.add('Create Index nlIndex ON 测试2 (年龄)');
adoq1.ExecSQL;
MessageBox(Application.Handle,
PChar('数据库:' + DbName+'创建完成'),
'OK',MB_OK + MB_ICONWARNING);
end;
 
使用JET SQL语言~
 
接受答案了.
 
这个问题没有解决,int和char类型正确,可是谁能在access2000中用create table创建出小数位数来,也就是如下create table 表名(字段名 numeric(8,3))或者用decimal总是出错,不知道各位高手试过没有。
 
顶部