Instead of creating each and every property, below query will help you created property on single fire.
Just replace "TABLENAME" with you table name.
Just replace "TABLENAME" with you table name.
DECLARE @COLUMN_NAME varchar(250) DECLARE @DATA_TYPE varchar(250) DECLARE c1 CURSOR FOR SELECT COLUMN_NAME, DATA_TYPE FROM information_schema.columns where table_name = 'TABLENAME' OPEN c1 FETCH NEXT FROM c1 INTO @COLUMN_NAME, @DATA_TYPE WHILE @@FETCH_STATUS = 0 BEGIN IF @DATA_TYPE = 'nvarchar' OR @DATA_TYPE = 'ntext' OR @DATA_TYPE = 'varchar' BEGIN SET @DATA_TYPE = 'string' END IF @DATA_TYPE = 'datetime' BEGIN SET @DATA_TYPE = 'DateTime' END DECLARE @pvar VARCHAR(100) SET @pvar = ' _' + @COLUMN_NAME PRINT 'private ' + @DATA_TYPE + @pvar + ' ;' PRINT 'public ' + @DATA_TYPE + ' ' + @COLUMN_NAME + ' {get{return '+ @pvar +';} set{'+ @pvar+'=value;} }' FETCH NEXT FROM c1 INTO @COLUMN_NAME, @DATA_TYPE END CLOSE c1 DEALLOCATE c1 GOIn the query above I have only added few data type. People can add more data type as per their need.
0 comments:
Post a Comment