大家的语句我好像看的不大明白,我知道建立db表: procedure TForm1.FormCreate(Sender: TObject); begin with ClientDataSet1 do begin with FieldDefs.AddFieldDef do begin DataType := ftInteger; Name := 'Field1'; end; with FieldDefs.AddFieldDef do begin DataType := ftString; Size := 10; Name := 'Field2'; end; with IndexDefs.AddIndexDef do begin Fields := 'Field1'; Name := 'IntIndex'; end; CreateDataSet; end; end;]但是怎么建立mdb或者dbf啊!!!!!!!!!!!!!!!!!!!!
8.12.1 Configuring an ODBC driver and alias for Delphi Question How to configure an ODBC driver and alias for Delphi? Answer CONTROL PANEL'S ODBC OPTION Delphi installs an ODBC option to the Windows Control Panel program. The ODBC option indicates the available data sources (drivers) installed for use by ODBC. As you will find by selecting the ODBC option, a number of formats are installed with Delphi and are seen in the main window titled Data Sources. Additional formats may be supported by the drivers installed and can be configured by selecting the Add... button. If a new driver is to be added or removed, 1. Select the Drivers... button from the Data Sources Window. From the drivers dialog, select the Add... button and provide the path where the ODBC driver will be found. 2. Return to the Data Sources Windows and include the possible data sources available through the new driver by selecting its Add... button. 3. To configure options available for a particular data source use the Setup... button. The function of the Setup... button will vary with each data format. Very often options like the working directory for the driver are configured in this area. Online help is available for each dialog involved with the ODBC option. BDE CONFIGURATION UTILITY After installing the ODBC driver, run the BDE Configuration utility to configure the database engine to use the new driver. 1. From the drivers page, select the New ODBC driver button. 2. A dialog titled Add ODBC driver will appear. The option for SQL link driver is what will distinguish the databases created using this ODBC driver. 3. Next select the default ODBC driver. Dropping down the list from the combobox will reveal the file types supported by ODBC drivers installed on the system. 4. Select the default data source for the ODBC driver. Having set the ODBC driver in step 3 above, the list of this combobox will have the data source names appropriate for use with the selected driver. 5. Select Ok. 6. Returning to the drivers page, select File/Save from the main menu to save this configuration. CREATING AN ALIAS IN THE DATABASE DESKTOP While this can be done from the BDE Configuration utility, it is more convenient overall to create ODBC aliases from the Database Desktop. 1. From the File menu, select Aliases... 2. From the resulting Alias Manager dialog, select New. 3. Type the name for your new alias in the area labeled Database Alias. 4. Use the drop down list of the Driver Type combobox to select the driver appropriate for this alias. Paradox and dBase tables are considered STANDARD. If the ODBC driver was properly configured in the BDE Configuration utility its name will appear in this list. 5. Additional options may appear depending upon the driver type you select. 6. When finished, select Keep New to store the new alias. Then select Ok. You will be prompted for whether or not to save the aliases to IDAPI.CFG. Select Okay. The alias will now be usable from both the Database Desktop and Delphi.
创建Access数据库var AccessEngine: DBEngine; i:Integer; begin AccessEngine:=CoDBEngine.Create; //通过DAO方式创建Access97格式的数据库 AccessEngine.CreateDatabase('C\Test1.mdb',';LANGID=0x0804;CP=936;COUNTRY=0;',dbEncrypt); end;
to :tikkypeng(千两狂死郎) 怎么健表啊!
建表?写SQL语句就可以了~~给你一个例子~~with ADOQuery1 do begin Close; SQL.Clear; SQL.Add('Create Table Test1 (TypeNo Char (10) NULL ,TypeName Char (20) Not NULL ,BedNumber int NULL)'); ExecSQL; end;
创建Access数据库var AccessEngine: DBEngine; i:Integer; begin AccessEngine:=CoDBEngine.Create; //通过DAO方式创建Access97格式的数据库 AccessEngine.CreateDatabase('C\Test1.mdb',';LANGID=0x0804;CP=936;COUNTRY=0;',dbEncrypt); end; 建表?写SQL语句就可以了~~给你一个例子~~with ADOQuery1 do begin Close; SQL.Clear; SQL.Add('Create Table Test1 (Field1 Char (10) NULL ,Field2 Char (20) Not NULL ,Field3 int NULL)'); ExecSQL; end;
http://www.csdn.net/expert/topic/301/301472.shtm
to :tikkypeng(千两狂死郎) : 你的代码还要引用什么东西吗?怎么不行啊!!!!!!!!!!!!!
function TransmitTemplateDatabase(SourceDBName:string; //源数据库名称
SourceTableName:string; //源表格组件
DestinationDBName:string; //目标数据库名称
DestinationTableName:string //目标表格组件
):Boolean;
begin
Result:=False;
try
//检查目标数据库是否已经存在
Table_Transmit_Destination.Active:=False;
Table_Transmit_Destination.DatabaseName:=DestinationDBName;
Table_Transmit_Destination.TableName:=DestinationTableName;
//若已经存在,则退出
if Table_Transmit_Destination.Exists then Exit;
Table_Transmit_Destination.Active:=False; //检查源数据库是否存在,若不存在则退出,若存在则连接
Table_Transmit_Source.Active:=False;
Table_Transmit_Source.DatabaseName:=SourceDBName;
Table_Transmit_Source.TableName:=SourceTableName;
if not Table_Transmit_Source.Exists then Exit;
Table_Transmit_Source.Active:=True; //创建并传输数据库表格
Table_Transmit_Destination.FieldDefs:=Table_Transmit_Source.FieldDefs;
Table_Transmit_Destination.IndexDefs.Assign(Table_Transmit_Source.IndexDefs);
Table_Transmit_Destination.CreateTable;
BatchMove_Transmit.Execute;
//设置传输成功标志
Result:=True;
finally
Table_Transmit_Destination.Active:=False;
Table_Transmit_Source.Active:=False;
end;
end;
BatchMove_Transmit为BatchMove组件,需要预先设置相关属性:Source、Destnation、Mode。或修改上面的为://传输模板数据库表格到指定数据库
function TransmitTemplateDatabase(SourceDBName:string; //源数据库名称
SourceTableName:string; //源表格组件
DestinationDBName:string; //目标数据库名称
DestinationTableName:string //目标表格组件
):Boolean;
begin
Result:=False;
try
//检查目标数据库是否已经存在
Table_Transmit_Destination.Active:=False;
Table_Transmit_Destination.DatabaseName:=DestinationDBName;
Table_Transmit_Destination.TableName:=DestinationTableName;
//若已经存在,则退出
if Table_Transmit_Destination.Exists then Exit;
Table_Transmit_Destination.Active:=False; //检查源数据库是否存在,若不存在则退出,若存在则连接
Table_Transmit_Source.Active:=False;
Table_Transmit_Source.DatabaseName:=SourceDBName;
Table_Transmit_Source.TableName:=SourceTableName;
if not Table_Transmit_Source.Exists then Exit;
Table_Transmit_Source.Active:=True; //创建并传输数据库表格
Table_Transmit_Destination.FieldDefs:=Table_Transmit_Source.FieldDefs;
Table_Transmit_Destination.IndexDefs.Assign(Table_Transmit_Source.IndexDefs);
Table_Transmit_Destination.CreateTable; BatchMove_Transmit.Source:=Table_Transmit_Source;
BatchMove_Transmit.Destination:=Table_Transmit_Destination;
BatchMove_Transmit.Mode:=batCopy;//etc BatchMove_Transmit.Execute;
//设置传输成功标志
Result:=True;
finally
Table_Transmit_Destination.Active:=False;
Table_Transmit_Source.Active:=False;
end;
end;
Table_Transmit_Destination、Table_Transmit_Source均为TTable对象,需要预先建立(放在Form或DBModule窗体上);SourceDBName:string; //源数据库名称(就是用于连接源数据表格的TDateBase组件的名称)
SourceTableName:string; //源表格组件名称
DestinationDBName:string; //目标数据库名称(就是用于连接目标数据表格的TDateBase组件的名称)DestinationTableName:string //目标表格组件名称
SourceDBName:string; //源数据库名称(就是用于连接源数据表格的TDateBase组件的数据库别名)
SourceTableName:string; //源表格组件名称
DestinationDBName:string; //目标数据库名称(就是用于连接目标数据表格的TDateBase组件的数据库别名)DestinationTableName:string //目标表格组件名称
procedure TForm1.FormCreate(Sender: TObject);
begin
with ClientDataSet1 do
begin
with FieldDefs.AddFieldDef do
begin
DataType := ftInteger;
Name := 'Field1';
end;
with FieldDefs.AddFieldDef do
begin
DataType := ftString;
Size := 10;
Name := 'Field2';
end;
with IndexDefs.AddIndexDef do begin
Fields := 'Field1';
Name := 'IntIndex';
end;
CreateDataSet;
end;
end;]但是怎么建立mdb或者dbf啊!!!!!!!!!!!!!!!!!!!!
同你上面的代码差不多。
dbf 简单一些,你只要把别名设置好成DB就可以了
mdb要设置ODBC,然后在设置bde,定义字段的过程是一样的
Question
How to configure an ODBC driver and alias for Delphi?
Answer
CONTROL PANEL'S ODBC OPTION
Delphi installs an ODBC option to the Windows Control Panel
program. The ODBC option indicates the available data sources
(drivers) installed for use by ODBC. As you will find by
selecting the ODBC option, a number of formats are installed
with Delphi and are seen in the main window titled Data Sources.
Additional formats may be supported by the drivers installed and
can be configured by selecting the Add... button.
If a new driver is to be added or removed,
1. Select the Drivers... button from the Data Sources Window.
From the drivers dialog, select the Add... button and provide
the path where the ODBC driver will be found.
2. Return to the Data Sources Windows and include the possible
data sources available through the new driver by selecting its
Add... button.
3. To configure options available for a particular data
source use the Setup... button. The function of the Setup...
button will vary with each data format. Very often options like
the working directory for the driver are configured in this
area.
Online help is available for each dialog involved with the ODBC
option.
BDE CONFIGURATION UTILITY
After installing the ODBC driver, run the BDE Configuration
utility to configure the database engine to use the new driver.
1. From the drivers page, select the New ODBC driver button.
2. A dialog titled Add ODBC driver will appear. The option for
SQL link driver is what will distinguish the databases created
using this ODBC driver.
3. Next select the default ODBC driver. Dropping down the list
from the combobox will reveal the file types supported by ODBC
drivers installed on the system.
4. Select the default data source for the ODBC driver. Having
set the ODBC driver in step 3 above, the list of this combobox
will have the data source names appropriate for use with the
selected driver.
5. Select Ok.
6. Returning to the drivers page, select File/Save from the main
menu to save this configuration.
CREATING AN ALIAS IN THE DATABASE DESKTOP
While this can be done from the BDE Configuration utility, it is
more convenient overall to create ODBC aliases from the Database
Desktop.
1. From the File menu, select Aliases...
2. From the resulting Alias Manager dialog, select New.
3. Type the name for your new alias in the area labeled Database
Alias.
4. Use the drop down list of the Driver Type combobox to select
the driver appropriate for this alias. Paradox and dBase tables
are considered STANDARD. If the ODBC driver was properly
configured in the BDE Configuration utility its name will
appear in this list.
5. Additional options may appear depending upon the driver type
you select.
6. When finished, select Keep New to store the new alias. Then
select Ok. You will be prompted for whether or not to save the
aliases to IDAPI.CFG. Select Okay.
The alias will now be usable from both the Database Desktop and
Delphi.
AccessEngine: DBEngine;
i:Integer;
begin
AccessEngine:=CoDBEngine.Create;
//通过DAO方式创建Access97格式的数据库
AccessEngine.CreateDatabase('C\Test1.mdb',';LANGID=0x0804;CP=936;COUNTRY=0;',dbEncrypt);
end;
怎么健表啊!
begin
Close;
SQL.Clear;
SQL.Add('Create Table Test1 (TypeNo Char (10) NULL ,TypeName Char (20) Not NULL ,BedNumber int NULL)');
ExecSQL;
end;
AccessEngine: DBEngine;
i:Integer;
begin
AccessEngine:=CoDBEngine.Create;
//通过DAO方式创建Access97格式的数据库
AccessEngine.CreateDatabase('C\Test1.mdb',';LANGID=0x0804;CP=936;COUNTRY=0;',dbEncrypt);
end; 建表?写SQL语句就可以了~~给你一个例子~~with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('Create Table Test1 (Field1 Char (10) NULL ,Field2 Char (20) Not NULL ,Field3 int NULL)');
ExecSQL;
end;
你的代码还要引用什么东西吗?怎么不行啊!!!!!!!!!!!!!