home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / mts4.cab / Account.VB_Step7_CreateTable.cls < prev    next >
Text File  |  1997-11-14  |  3KB  |  110 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CreateTable"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. ' Filename: Account.vbp
  11. '
  12. ' Description:  CreateTable Class
  13. '
  14. ' This file is provided as part of the Microsoft Transaction Server Samples
  15. '
  16. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
  17. ' WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
  18. ' INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
  19. ' OF MERCHANTABILITY AND/OR FITNESS FOR A  PARTICULAR
  20. ' PURPOSE.
  21. '
  22. ' Copyright (C) 1997 Microsoft Corporation, All rights reserved
  23.  
  24. Option Explicit
  25.  
  26. Private Const ERROR_NUMBER = vbObjectError + 0 ' we always return the same error number
  27. Private Const strConnect = "FILEDSN=MTSSamples"
  28.  
  29. Public Sub CreateAccount()
  30.     
  31.     On Error GoTo ErrorHandler
  32.     
  33.     Dim adoConn As New ADODB.Connection
  34.     adoConn.Open strConnect
  35.    
  36.     ' Add Account Table
  37.     Dim strSQL As String
  38.     
  39.     strSQL = "If not exists (Select name from sysobjects where name = 'Account')" & vbCrLf & _
  40.             "BEGIN" & vbCrLf & _
  41.             "CREATE TABLE dbo.Account (" & vbCrLf & _
  42.                 "AccountNo int NOT NULL ," & vbCrLf & _
  43.                 "Balance int NULL ," & vbCrLf & _
  44.                 "CONSTRAINT PK___1__10 PRIMARY KEY  CLUSTERED" & vbCrLf & _
  45.                 "(" & vbCrLf & _
  46.                     "AccountNo" & vbCrLf & _
  47.                 ")" & vbCrLf & _
  48.             ")" & vbCrLf & _
  49.             "INSERT INTO Account VALUES (1,1000)" & vbCrLf & _
  50.             "INSERT INTO Account VALUES (2,1000)" & vbCrLf & _
  51.             "END" & vbCrLf
  52.     
  53.     adoConn.Execute strSQL
  54.     
  55.     Set adoConn = Nothing
  56.     
  57.     GetObjectContext.SetComplete
  58.     
  59.     Exit Sub
  60.     
  61. ErrorHandler:
  62.  
  63.     If Not adoConn Is Nothing Then
  64.         Set adoConn = Nothing
  65.     End If
  66.     
  67.     GetObjectContext.SetAbort
  68.     
  69.     Err.Raise Err.Number, "Bank.CreateTable.CreateAccount", Err.Description
  70.     
  71. End Sub
  72.  
  73.  
  74. Public Sub CreateReceipt()
  75.     
  76.     On Error GoTo ErrorHandler
  77.     
  78.     Dim adoConn As New ADODB.Connection
  79.     adoConn.Open strConnect
  80.    
  81.     ' Add ReceiptNo Table
  82.     Dim strSQL As String
  83.     strSQL = strSQL & _
  84.             "If not exists (Select name from sysobjects where name = 'Receipt')" & vbCrLf & _
  85.             "BEGIN" & vbCrLf & _
  86.             "CREATE TABLE Receipt (NextReceipt int)" & vbCrLf & _
  87.             "INSERT INTO Receipt VALUES (1000)" & vbCrLf & _
  88.             "END"
  89.     adoConn.Execute strSQL
  90.   
  91.     Set adoConn = Nothing
  92.     
  93.     GetObjectContext.SetComplete
  94.     
  95.     Exit Sub
  96.     
  97. ErrorHandler:
  98.  
  99.     If Not adoConn Is Nothing Then
  100.         Set adoConn = Nothing
  101.     End If
  102.     
  103.     GetObjectContext.SetAbort
  104.     
  105.     Err.Raise Err.Number, "Bank.CreateTable.CreateReceipt", Err.Description
  106.     
  107. End Sub
  108.  
  109.  
  110.