Me.CreateVIEwBtn, Me.CreateSPBtn, Me.CreateTableBtn, Me.CreateDBBtn})
Me.Name = "Form1"
Me.Text = "動態創建SQL Server數據庫、表、存儲過程等架構信息"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
' 創建數據庫
Private Sub CreateDBBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CreateDBBtn.Click
conn = New SqlConnection(ConnectionString)
' 打開連接
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
'MyDataBase為數據庫名稱
Dim sql As String = "CREATE DATABASE MyDataBase ON PRIMARY (Name=MyDataBase_data, filename = " + _
54com.cn
"'D:\MyDataBase.mdf', size=3," + "maxsize=5, filegrowth=10%) log on" + "(name=MyDataBase_log, " + _
"filename='D:\MyDataBase.ldf',size=3," + "maxsize=20,filegrowth=1)"
cmd = New SqlCommand(sql, conn)
Try
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message.ToString())
End Try
End Sub
'創建表
Private Sub CreateTableBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CreateTableBtn.Click
conn = New SqlConnection(ConnectionString)
' 打開連接
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = "Data Source=.;Initial Catalog=MyDataBase;User Id=sa;PassWord=;"
conn.ConnectionString = ConnectionString
conn.Open()
sql = "CREATE TABLE myTable" + "(myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," + _
"myName CHAR(50) NOT Null, myAddress CHAR(255), myValues FLOAT)"
cmd = New SqlCommand(sql, conn)
Try
cmd.ExecuteNonQuery()
' 添加紀錄
54com.cn
sql = "INSERT INTO myTable(myId, myName, myAddress, myValues) " + _
"VALUES (1001, _'【孟憲會之精彩世界】之一', 'http://XML.sz.luohuedu.Net/', 100 ) "
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
sql = "INSERT INTO myTable(myId, myName, myAddress, myValues) " + _
"VALUES (1002, '【孟憲會之精彩世界】之二', 'http://www.erp800.com/net_lover/', 99) "