也许你早已厌倦了做Delphi组件时的声明,下面是我写的小视图,也许能帮上你的忙。
创建一个视图:如下
CREATE VIEW dbo.TP
AS
SELECT Names = 'property ' + syscolumns.name + ':',
theType = CASE WHEN systypes.name = 'Varchar' THEN 'String'
when systypes.name = 'int' THEN 'integer'
when systypes.name = 'text'then 'String'
when systypes.name = 'DateTime' then 'TDateTime'
ELSE systypes.name
END, other = ' read Get' + syscolumns.Name + ';'
FROM syscolumns LEFT JOIN
systypes ON syscolumns.xtype = systypes.xtype
WHERE id IN
(SELECT ID
FROM sysobjects
WHERE Name = 'T_SUBMIT')
--Name写入你想要的表。
在查询分析器里写入:
select Names+theType+other from TP
F5结果:
property CorpName:String read GetCorpName;
property SubmitID:integer read GetSubmitID;
property SubmitName:String read GetSubmitName;
property SubmitInputName:String read GetSubmitInputName;
property Title:String read GetTitle;
property Name:String read GetName;
property Country:String read GetCountry;
property BelongCorp:String read GetBelongCorp;
property Province:String read GetProvince;
property Tel:String read GetTel;
property Fax:String read GetFax;
property Email:String read GetEmail;
property Addr:String read GetAddr;
property ReceiptCountry:String read GetReceiptCountry;
property DeliveryCountry:String read GetDeliveryCountry;
创建一个视图:如下
CREATE VIEW dbo.TP
AS
SELECT Names = 'property ' + syscolumns.name + ':',
theType = CASE WHEN systypes.name = 'Varchar' THEN 'String'
when systypes.name = 'int' THEN 'integer'
when systypes.name = 'text'then 'String'
when systypes.name = 'DateTime' then 'TDateTime'
ELSE systypes.name
END, other = ' read Get' + syscolumns.Name + ';'
FROM syscolumns LEFT JOIN
systypes ON syscolumns.xtype = systypes.xtype
WHERE id IN
(SELECT ID
FROM sysobjects
WHERE Name = 'T_SUBMIT')
--Name写入你想要的表。
在查询分析器里写入:
select Names+theType+other from TP
F5结果:
property CorpName:String read GetCorpName;
property SubmitID:integer read GetSubmitID;
property SubmitName:String read GetSubmitName;
property SubmitInputName:String read GetSubmitInputName;
property Title:String read GetTitle;
property Name:String read GetName;
property Country:String read GetCountry;
property BelongCorp:String read GetBelongCorp;
property Province:String read GetProvince;
property Tel:String read GetTel;
property Fax:String read GetFax;
property Email:String read GetEmail;
property Addr:String read GetAddr;
property ReceiptCountry:String read GetReceiptCountry;
property DeliveryCountry:String read GetDeliveryCountry;
我应该补充一下,我做的多数是数据层,也就是数据实体类。
通过该类来进行数据操作,而在创建实体类时很多与数据库中的表打教到,
我做这段,是避免了你一个一个到数据库中去对应字段名与数据类型。
和繁琐的Delphi属性声明。
to; imageonline(不交房租)
他说对了,只有编写对应表的实体类时,才能体会这个视图的用处。
MSN:[email protected]