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--表名

上一篇:C#--List集合转DataTable


下一篇:C# 反射实现DataTable转ModelList