if(object_id('generatecode')) isnotnulldropproc generatecode go CREATEproc generatecode @tablevarchar(50) as declare@sqlstrvarchar(2000) createtable #tmp ( column_name varchar(20), type_name varchar(20), length varchar(10) ) createtable #text(n_text varchar(1000)) select@sqlstr=' insert into #tmp (column_name,type_name,length) select name,type_name,a.prec from syscolumns a ,master.dbo.spt_datatype_info b where id = object_id(N'''+@table+''') and OBJECTPROPERTY(id, N''IsUserTable'') =1 and a.xtype=b.ss_dtype and a.length = isnull(b.fixlen, a.length) AND isnull(b.AUTO_INCREMENT,0) = isnull(ColumnProperty (a.id, a.name, ''IsIdentity''),0) AND (b.ODBCVer is null or b.ODBCVer = 2) ' execute(@sqlstr) declare@namevarchar(20) declare@typevarchar(20) declare cur cursor scroll forselect column_name,type_name from #tmp open cur fetchnextfrom cur into@name,@type while@@fetch_status=0 begin insertinto #textvalues('private '+casewhen@type='varchar'or@type='nvarchar'or@type='char'or@type='text'or@type='ntext'then'String '+@name+';' when@type='int'or@type='int identity'then'int '+@name+';' when@type='datetime'or@type='smalldatetime'then'DateTime '+@name+';' when@type='bit'then'bool '+@name+';' when@type='decimal'or@type='numeric'or@type='money'or@type='smallmoney'then'decimal '+@name+';' when@type='float'then'double '+@name+';' when@type='binary'or@type='image'or@type='varbinary'or@type='timestamp'then'byte[] '+@name+';' when@type='real'then'single '+@name+';' end ) fetchnextfrom cur into@name,@type end fetch absolute 1from cur into@name,@type while@@fetch_status=0 begin insertinto #textvalues('public '+casewhen@type='varchar'or@type='nvarchar'or@type='char'or@type='text'or@type='ntext'then'String '+upper(@name) when@type='int'or@type='int identity'then'int '+upper(@name) when@type='datetime'or@type='smalldatetime'then'DateTime '+upper(@name) when@type='bit'then'bool '+upper(@name) when@type='decimal'or@type='numeric'or@type='money'or@type='smallmoney'then'decimal '+@name when@type='float'then'double '+@name when@type='binary'or@type='image'or@type='varbinary'or@type='timestamp'then'byte[] '+@name when@type='real'then'single '+@name end ) insertinto #textvalues('{') insertinto #textvalues('get{return this.'+@name+';}') insertinto #textvalues('set{this.'+@name+' = value;}') insertinto #textvalues('}') fetchnextfrom cur into@name,@type end close cur deallocate cur select*from #text droptable #tmp droptable #text GO exec generatecode 'userinfo'