Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Dec 10

Written by: Steve Gray
12/10/2010 12:56 PM  RssIcon

 

The is code that will create a VB class based on a table. There are helper scripts needed, find them here

Code Snippet
  1. IF EXISTS (SELECT name
  2.     FROM   sysobjects
  3.     WHERE  name = N'sp_CreateVBClassForATable'
  4.     AND    type = 'P')
  5.     DROP PROCEDURE sp_CreateVBClassForATable
  6. GO
  7.  
  8. CREATE PROCEDURE sp_CreateVBClassForATable
  9. -- sp_CreateVBClassForATable 'POP10300'
  10.  
  11. --sp_sps
  12.  
  13.     @vchrTable varchar(255)
  14.     
  15. AS
  16. set nocount on
  17.  
  18. DECLARE
  19.     @FS INT ,
  20.     @RC INT ,
  21.     @vchrLine varchar(1000),
  22.     @vchrSP_Prefix varchar(10),
  23.     @vchrSelectByIDSuffix varchar(20),
  24.     @vchrDeleteSuffix varchar(20),
  25.     @vchrUpdateSuffix varchar(20),
  26.     @vchrInsertSuffix varchar(20),
  27.     @vchrSelectByIDProc varchar(255),
  28.     @vchrUpdateProc varchar(255),
  29.     @vchrInsertProc varchar(255),
  30.     @vchrDeleteProc varchar(255),
  31.     @vchrDataClass varchar(255)
  32.  
  33. --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  34. --    IMPORTANT - EDIT THIS TEXT
  35. --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  36. SELECT
  37.     @vchrSP_Prefix = 'FP_',
  38.     @vchrSelectByIDSuffix = '_SEL_byID',
  39.     @vchrDeleteSuffix = '_DEL',
  40.     @vchrUpdateSuffix = '_UPD',
  41.     @vchrInsertSuffix = '_INS',
  42.     @vchrDataClass = 'SPs' + '.'
  43.  
  44. --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  45. -- END EDITING
  46. --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  47.  
  48. --===================================================================================
  49. --begin processing
  50. --===================================================================================
  51.  
  52. --write the class header
  53. print 'Public Class ' + @vchrTable
  54.   print '#Region ' + char(34) + 'Properties'+ char(34)
  55. --=======================================================
  56. --write the fields
  57. --=======================================================
  58. DECLARE @vchrField varchar(255),
  59.     @vchrFieldType varchar(255)
  60.  
  61. DECLARE curName CURSOR LOCAL FAST_FORWARD FOR
  62.     SELECT  c.Name ,
  63.             dbo.f_4P_columnTypeVB(c.xtype)
  64.         from sysobjects o (nolock)
  65.             join syscolumns c (nolock) on o.id = c.id    
  66.         where o.[name] = @vchrTable
  67.             and o.xtype = 'U'
  68.         order by c.colorder
  69.  
  70. OPEN curName
  71. WHILE 1=1
  72. BEGIN
  73.     FETCH NEXT FROM curName INTO @vchrField,@vchrFieldType
  74.     if @@fetch_status <> 0 begin
  75.         break
  76.     end
  77.  
  78.     --write the field declaration
  79.     print   '    Public ' + @vchrField + ' as ' + @vchrFieldType
  80.  
  81. END
  82. CLOSE curName
  83. DEALLOCATE curName
  84. print '#End Region'
  85. --=======================================================
  86. -- end fields
  87. --=======================================================
  88.  
  89.  
  90. select
  91.     @vchrSelectByIDProc = @vchrSP_Prefix + @vchrTable + @vchrSelectByIDSuffix,
  92.     @vchrUpdateProc = @vchrSP_Prefix + @vchrTable + @vchrUpdateSuffix,
  93.     @vchrInsertProc = @vchrSP_Prefix + @vchrTable + @vchrInsertSuffix,
  94.     @vchrDeleteProc = @vchrSP_Prefix + @vchrTable + @vchrDeleteSuffix
  95.  
  96. --=======================================================
  97. --write the 'new' subroutine
  98. --=======================================================
  99. --print a blank line
  100. print ''
  101.  
  102. exec sp_NEW @vchrSelectByIDProc, @vchrTable,@vchrDataClass
  103.  
  104. --=======================================================
  105. --write the 'save' subroutine
  106. --=======================================================
  107. --print a blank line
  108. print ''
  109.  
  110. exec sp_SAVE @vchrUpdateProc, @vchrTable,@vchrDataClass
  111.  
  112. --=======================================================
  113. --write the class footer
  114. --=======================================================
  115.    print'End Class ' + char(39) + @vchrTable
  116.  
  117.  
  118.  
  119.  
  120. go
  121.  
  122. grant exec on sp_CreateVBClassForATable to public
  123.  
  124. --sp_sps

Tags:
Categories:
Location: Blogs Parent Separator DEVSHED Blogs Child Separator SQL
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us