日期:2011-03-13 浏览次数:20452 次
CREATE TABLE [dbo].[Employees] ([Name] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,[Rsvp] [int] NULL ,[Requests] [nvarchar] (4000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY];ALTER TABLE [dbo].[Employees] WITH NOCHECK ADD CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED ([Name]) ON [PRIMARY];
Imports System.IOImports System.Reflection
Private Function GetSql(ByVal Name As String) As String Try ' Get the current assembly. Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly() ' Resources are named using a fully qualified name. Dim strm As Stream = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + Name) ' Read the contents of the embedded file. Dim reader As StreamReader = New StreamReader(strm) Return reader.ReadToEnd() Catch ex As Exception MsgBox("In GetSQL: " & ex.Message) Throw ex End TryEnd FunctionPrivate Sub ExecuteSql(ByVal DatabaseName As String, ByVal Sql As String) Dim Command As New SqlClient.SqlCommand(Sql, sqlConnection1) Command.Connection.Open() Command.Connection.ChangeDatabase(DatabaseName) Try Command.ExecuteNonQuery() Finally ' Finally, blocks are a great way to ensure that the connection ' is always closed. Command.Connection.Close() End TryEnd SubProtected Sub AddDBTable(ByVal strDBName As String) Try ' Create the database. ExecuteSql("master", "CREATE DATABASE " + strDBName) ' Create the tables. ExecuteSql(strDBName, GetSql("sql.txt")) Catch ex As Exception ' Report any errors and abort. MsgBox("In exception handler: " & ex.Message) Throw ex End TryEnd SubPublic Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary) MyBase.Install(stateSaver) AddDBTable(Me.Context.Parameters.Item("dbname"))End Sub