其他分享
首页 > 其他分享> > DataTable 表生成代码(zml)

DataTable 表生成代码(zml)

作者:互联网

DECLARE @TableName varchar(50)
SET @TableName='Branch_Charge'
select 'DataTable T_'+@TableName+' = new DataTable();'

select 'DataColumn '+col.NAME+' = new DataColumn("'+col.NAME+'", typeof(string));'
FROM dbo.syscolumns col
inner JOIN dbo.sysobjects obj ON col.id = obj.id
AND obj.xtype = 'U'
AND obj.status >= 0
WHERE obj.name = @TableName --表名


select 'T_'+@TableName+'.Columns.Add('+col.NAME+');'
FROM dbo.syscolumns col
inner JOIN dbo.sysobjects obj ON col.id = obj.id
AND obj.xtype = 'U'
AND obj.status >= 0
WHERE obj.name = @TableName--表名


select 'row['+CONVERT(varchar(50),ROW_NUMBER() OVER(ORDER BY col.colorder )-1)+'] =t.'+col.NAME+';'
FROM dbo.syscolumns col
inner JOIN dbo.sysobjects obj ON col.id = obj.id
AND obj.xtype = 'U'
AND obj.status >= 0
WHERE obj.name = @TableName--表名

标签:obj,dbo,zml,代码,TableName,col,id,DataTable,select
来源: https://www.cnblogs.com/sanshengshitouhua/p/14439870.html