
DSN\MS
ACCESS
DATABASE,点击"Configure...",在ODBC
Microsoft
Access
Setup中点击"Select..."选中你的Access库,点击“OK”回到ODBC
Microsoft
Access
Setup,点击"Advanced..."设你的用户名和暗码,依次点击“OK”“肯定”退出ODBC进入DELPHI,把你的Table1的DatsbaseName属性设为MS
Access
Database,再将Table1的Active属性设为"True",在DBGrid1中就可在设计时看见你的数据了。当然,这是最简单的一个例子。OK?!
以下是一个示例。供参考。 (它是由 dBASEvierer 自动生成的单元)unit 1
{***********************************************************************}
{ }
{ The following is a function that creates one or more tables in the }
{ folder "aDbase" specified as a parameter. If the tables are }
{ successfully created and opened, True is returned. "AOwner" is a }
{ component that is to own Table0 used to define the various tables. }
{ }
{ This function may be used as is or the appropriate sections may be }
{ copied into code of the writer's choice. }
{ }
{ Code generated by dBASEviewer, written by Douglas P. Baird - }
{ dpbaird@sprynet.com Please give a credit if this code is used. }
{ }
{***********************************************************************}
interface
uses classes
function CreateTables(aDbase: string AOwner: TComponent): Boolean
implementation
uses dbtables, SysUtils, db, Dialogs
function CreateTables(aDbase: string AOwner: TComponent): Boolean
var
Table0: TTable
begin
Table0 := TTable.Create(AOwner)
{ Create 1.DBF }
with Table0 do begin
try
DatabaseName := aDbase
TableName := '1.DBF'
TableType := ttDBase
TableLevel := 7
with FieldDefs do begin
Clear
with AddFieldDef do begin
Name := '自动'
DataType := ftAutoInc
end
with AddFieldDef do begin
Name := '日期'
DataType :=ftDateTime
end
with AddFieldDef do begin
Name := '分类'
DataType :=ftString
Size := 16
end
with AddFieldDef do begin
Name := '知识主题'
DataType :=ftString
Size := 60
end
with AddFieldDef do begin
Name := '索引关键字'
DataType :=ftString
Size := 20
end
with AddFieldDef do begin
Name := '知识内容'
DataType :=ftMemo
end
with AddFieldDef do begin
Name := '提交'
DataType :=ftBoolean
end
with AddFieldDef do begin
Name := 'blob'
DataType := ftTypedBinary
end
with AddFieldDef do begin
Name := 'ext'
DataType :=ftString
Size := 5
end
end
{od with}
IndexDefs.Clear
with IndexDefs.AddIndexDef do begin
Name := '分类'
Fields := '分类'
Options := []
end
{od with}
with IndexDefs.AddIndexDef do begin
Name := '日期'
Fields := '日期'
Options := []
end
{od with}
except
on E: Exception do begin
MessageDlg(E.Message,mtError,[mbOk],0)
Result := False
Exit
end
{od on}
end {try}
Result := True
try
CreateTable
except
on E: Exception do begin
MessageDlg('Error creating table. '+E.Message,mtError,[mbOk],0)
Result := False
end
{od on}
end {try}
end
{od with Table0}
Table0.Free
end
end.
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)