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