成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術文章
文章詳情頁

動態創建SQL Server數據庫表存儲過程

瀏覽:211日期:2023-11-07 14:53:54

下面是利用SQL語句創建數據庫、表、存儲過程、視圖、索引、規則、修改表、查看數據等的方法。所要增加的控件如下:

Imports System.Data Imports System.Data.SqlClient

Public Class Form1 Inherits System.Windows.Forms.Form Private ConnectionString As String = "Data Source=.;Initial Catalog=;User Id=sa;Password=;" Private reader As SqlDataReader = Nothing Private conn As SqlConnection = Nothing Private cmd As SqlCommand = Nothing Private AlterTableBtn As System.Windows.Forms.Button Private sql As String = Nothing Private CreateOthersBtn As System.Windows.Forms.Button

#Region " Windows 窗體設計器生成的代碼 " '窗體重寫處置以清理組件列表。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Public Sub New() MyBase.New() InitializeComponent() End Sub Private components As System.ComponentModel.IContainer Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid Friend WithEvents CreateDBBtn As System.Windows.Forms.Button Friend WithEvents CreateTableBtn As System.Windows.Forms.Button Friend WithEvents CreateSPBtn As System.Windows.Forms.Button Friend WithEvents CreateViewBtn As System.Windows.Forms.Button Friend WithEvents btnAlterTable As System.Windows.Forms.Button Friend WithEvents btnCreateOthers As System.Windows.Forms.Button Friend WithEvents btnDropTable As System.Windows.Forms.Button Friend WithEvents btnViewData As System.Windows.Forms.Button Friend WithEvents btnViewSP As System.Windows.Forms.Button Friend WithEvents btnViewView As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.CreateDBBtn = New System.Windows.Forms.Button() Me.CreateTableBtn = New System.Windows.Forms.Button() Me.CreateSPBtn = New System.Windows.Forms.Button() Me.CreateViewBtn = New System.Windows.Forms.Button() Me.btnAlterTable = New System.Windows.Forms.Button() Me.btnCreateOthers = New System.Windows.Forms.Button() Me.btnDropTable = New System.Windows.Forms.Button() Me.btnViewData = New System.Windows.Forms.Button() Me.btnViewSP = New System.Windows.Forms.Button() Me.btnViewView = New System.Windows.Forms.Button() Me.DataGrid1 = New System.Windows.Forms.DataGrid() CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'CreateDBBtn ' Me.CreateDBBtn.Location = New System.Drawing.Point(19, 9) Me.CreateDBBtn.Name = "CreateDBBtn" Me.CreateDBBtn.Size = New System.Drawing.Size(104, 23) Me.CreateDBBtn.TabIndex = 0 Me.CreateDBBtn.Text = "創建數據庫" ' 'CreateTableBtn ' Me.CreateTableBtn.Location = New System.Drawing.Point(139, 9) Me.CreateTableBtn.Name = "CreateTableBtn" Me.CreateTableBtn.TabIndex = 1 Me.CreateTableBtn.Text = "創建表" ' 'CreateSPBtn ' Me.CreateSPBtn.Location = New System.Drawing.Point(230, 9) Me.CreateSPBtn.Name = "CreateSPBtn" Me.CreateSPBtn.Size = New System.Drawing.Size(104, 23) Me.CreateSPBtn.TabIndex = 2 Me.CreateSPBtn.Text = "創建存儲過程" ' 'CreateViewBtn ' Me.CreateViewBtn.Location = New System.Drawing.Point(350, 9) Me.CreateViewBtn.Name = "CreateViewBtn" Me.CreateViewBtn.TabIndex = 3 Me.CreateViewBtn.Text = "創建視圖" ' 'btnAlterTable ' Me.btnAlterTable.Location = New System.Drawing.Point(441, 9) Me.btnAlterTable.Name = "btnAlterTable" Me.btnAlterTable.TabIndex = 4 Me.btnAlterTable.Text = "修改表" ' 'btnCreateOthers ' Me.btnCreateOthers.Location = New System.Drawing.Point(17, 43) Me.btnCreateOthers.Name = "btnCreateOthers" Me.btnCreateOthers.Size = New System.Drawing.Size(104, 23) Me.btnCreateOthers.TabIndex = 5 Me.btnCreateOthers.Text = "創建規則和索引" ' 'btnDropTable ' Me.btnDropTable.Location = New System.Drawing.Point(138, 43) Me.btnDropTable.Name = "btnDropTable" Me.btnDropTable.TabIndex = 6 Me.btnDropTable.Text = "刪除表" ' 'btnViewData ' Me.btnViewData.Location = New System.Drawing.Point(351, 43) Me.btnViewData.Name = "btnViewData" Me.btnViewData.TabIndex = 7 Me.btnViewData.Text = "查看數據" ' 'btnViewSP ' Me.btnViewSP.Location = New System.Drawing.Point(230, 43) Me.btnViewSP.Name = "btnViewSP" Me.btnViewSP.Size = New System.Drawing.Size(104, 23) Me.btnViewSP.TabIndex = 8 Me.btnViewSP.Text = "查看存儲過程" ' 'btnViewView ' Me.btnViewView.Location = New System.Drawing.Point(443, 43) Me.btnViewView.Name = "btnViewView" Me.btnViewView.TabIndex = 9 Me.btnViewView.Text = "查看視圖" ' 'DataGrid1 ' Me.DataGrid1.DataMember = "" Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.DataGrid1.Location = New System.Drawing.Point(20, 76) Me.DataGrid1.Name = "DataGrid1" Me.DataGrid1.Size = New System.Drawing.Size(500, 183) Me.DataGrid1.TabIndex = 10 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(538, 281) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.DataGrid1, Me.btnViewView, _ Me.btnViewSP, Me.btnViewData, Me.btnDropTable, Me.btnCreateOthers,

Me.btnAlterTable, _ 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 = " + _ "'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() ' 添加紀錄 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) " cmd = New SqlCommand(sql, conn) cmd.ExecuteNonQuery() sql = "INSERT INTO myTable(myId, myName, myAddress, myValues) " + _ "VALUES (1003, '【孟憲會之精彩世界】之三', 'http://xml.sz.luohuedu.net/', 99) " cmd = New SqlCommand(sql, conn) cmd.ExecuteNonQuery() sql = "INSERT INTO myTable(myId, myName, myAddress, myValues) " + _ "VALUES (1004, '【孟憲會之精彩世界】之四', 'http://www.erp800.com/net_lover/', 100) " cmd = New SqlCommand(sql, conn) cmd.ExecuteNonQuery() Catch ae As SqlException MessageBox.Show(ae.Message.ToString()) End Try

End Sub '創建存儲過程 Private Sub CreateSPBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles CreateSPBtn.Click sql = "CREATE PROCEDURE myProc AS" + " SELECT myName, myAddress FROM myTable GO" ExecuteSQLStmt(sql) End Sub '創建視圖 Private Sub CreateViewBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles CreateViewBtn.Click sql = "CREATE VIEW myView AS SELECT myName FROM myTable" ExecuteSQLStmt(sql)

End Sub '修改表 Private Sub btnAlterTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles btnAlterTable.Click sql = "ALTER TABLE MyTable ADD newCol datetime NOT NULL DEFAULT (getdate())" ExecuteSQLStmt(sql) End Sub '創建規則和索引 Private Sub btnCreateOthers_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) _ Handles btnCreateOthers.Click sql = "CREATE UNIQUE INDEX " + "myIdx ON myTable(myName)" ExecuteSQLStmt(sql)

sql = "CREATE RULE myRule " + "AS @myValues >= 90 AND @myValues < 9999" ExecuteSQLStmt(sql) End Sub

'刪除表 Private Sub btnDropTable_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) _ Handles btnDropTable.Click Dim sql As String = "DROP TABLE MyTable" ExecuteSQLStmt(sql) End Sub '瀏覽表數據 Private Sub btnViewData_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) _ Handles btnViewData.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() Dim da As New SqlDataAdapter("SELECT * FROM myTable", conn) Dim ds As New DataSet("myTable") da.Fill(ds, "myTable") DataGrid1.DataSource = ds.Tables("myTable").DefaultView End Sub '瀏覽存儲過程 Private Sub btnViewSP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles btnViewSP.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() Dim da As New SqlDataAdapter("myProc", conn) Dim ds As New DataSet("SP") da.Fill(ds, "SP") DataGrid1.DataSource = ds.DefaultViewManager End Sub '瀏覽視圖 Private Sub btnViewView_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) _ Handles btnViewView.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() Dim da As New SqlDataAdapter("SELECT * FROM myView", conn) Dim ds As New DataSet() da.Fill(ds) DataGrid1.DataSource = ds.DefaultViewManager End Sub

Private Sub ExecuteSQLStmt(ByVal sql As String) 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() cmd = New SqlCommand(sql, conn) Try cmd.ExecuteNonQuery() Catch ae As SqlException MessageBox.Show(ae.Message.ToString()) End Try End Sub End Class

標簽: Sql Server 數據庫
相關文章:
成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久
日本韩国欧美一区| 波多野结衣中文字幕一区二区三区| 国产成人在线看| 在线日韩一区二区| 亚洲第一精品在线| 久久精品在线| 五月天精品一区二区三区| 国产伦精品一区二区三区视频孕妇| 国产精品乱人伦中文| 色综合久久中文综合久久牛| 日韩免费看的电影| 成人亚洲精品久久久久软件| 欧美一区欧美二区| 久久99精品久久久| 678五月天丁香亚洲综合网| 久久97超碰色| 欧美午夜视频网站| 老司机一区二区| 欧美日韩免费电影| 国产老妇另类xxxxx| 日韩一区二区三区免费看 | 亚洲色图制服丝袜| 国语自产精品视频在线看抢先版结局 | 天天av天天翘天天综合网| 亚洲视频二区| 视频一区在线播放| 欧美性生活久久| 丁香婷婷综合色啪| 久久伊99综合婷婷久久伊| 91丨porny丨国产入口| 久久久九九九九| 亚洲欧洲午夜| 丝袜美腿亚洲综合| 欧美男男青年gay1069videost| 精品伊人久久久久7777人| 6080国产精品一区二区| 成人性生交大片免费看中文| 久久久综合视频| 伊人婷婷久久| 一级女性全黄久久生活片免费| 国产精品一页| 另类小说视频一区二区| 91精品国产乱码久久蜜臀| 成人视屏免费看| 久久精品人人爽人人爽| 一区在线播放| 天堂久久一区二区三区| 在线播放/欧美激情| 91色乱码一区二区三区| 亚洲视频综合在线| 色噜噜狠狠成人网p站| 国产麻豆视频精品| 国产亚洲精品资源在线26u| 亚洲欧洲三级| 日韩福利视频导航| 日韩免费观看高清完整版在线观看| 欧美 日韩 国产在线 | 亚洲午夜久久久久中文字幕久| 久久九九国产| 国产麻豆精品视频| 国产女人水真多18毛片18精品视频| 在线欧美一区| 久久精品国产77777蜜臀| 精品久久久久av影院| 亚洲国产日韩在线| 久久精品国产99国产精品| 2024国产精品| 国产精品毛片在线| 国产传媒久久文化传媒| 国产精品拍天天在线| 色成人在线视频| 成人av电影在线| 亚洲欧美激情视频在线观看一区二区三区 | 欧美一级二级在线观看| 国产在线视频欧美一区二区三区| 三级不卡在线观看| 久久―日本道色综合久久| 国产欧美日韩一区二区三区在线| 麻豆精品一区二区av白丝在线 | 久久精品久久99精品久久| 久久免费午夜影院| 老司机精品福利视频| 99麻豆久久久国产精品免费| 午夜精品久久久久影视| 欧美tickling挠脚心丨vk| 在线亚洲观看| 国产a久久麻豆| 亚洲一区二区三区四区在线免费观看 | 欧美乱妇23p| 欧美成人精品| 免费在线成人网| 欧美激情一区二区三区四区| 色婷婷国产精品久久包臀| 欧美精品18| 久久99国内精品| 亚洲卡通欧美制服中文| 日韩一区国产二区欧美三区| 亚洲精品美女久久7777777| 国产激情91久久精品导航| 国产精品视频免费| 欧美日本国产一区| 亚洲国产日韩在线| 国产成人综合网| 一卡二卡欧美日韩| 久久久精品影视| 欧美剧情片在线观看| 国产精品女主播一区二区三区| 99久久精品国产精品久久| 美女一区二区视频| 亚洲免费毛片网站| 欧美精品一区二区三区蜜桃| 色网综合在线观看| 黄色成人在线网址| 风间由美一区二区av101| 亚洲bdsm女犯bdsm网站| 国产欧美精品国产国产专区| 欧美色倩网站大全免费| 亚洲精一区二区三区| 99久久综合色| 麻豆成人免费电影| 亚洲人成7777| 久久综合色天天久久综合图片| 欧美性生活一区| 国产精品久久波多野结衣| 成人app在线| 精品一区二区三区香蕉蜜桃| 一区二区三区加勒比av| 国产视频一区二区在线观看| 欧美日韩国产一二三| 免费在线亚洲| 激情另类综合| 99久久99精品久久久久久| 久久成人久久鬼色| 亚洲国产精品天堂| 亚洲天堂精品在线观看| 久久久精品黄色| 日韩欧美电影一区| 欧美蜜桃一区二区三区| 久久黄色影院| 在线观看视频免费一区二区三区| av激情成人网| 国产成人免费视频一区| 久久国产精品免费| 亚洲国产成人va在线观看天堂| 成人免费在线播放视频| 久久九九全国免费| 日韩一区二区电影| 欧美精品黑人性xxxx| 久久中文在线| av成人毛片| 亚洲高清视频在线观看| 欧美久久成人| 欧美在线日韩精品| 91在线视频免费观看| 成人免费不卡视频| 高清shemale亚洲人妖| 激情久久五月天| 久久精品国产99久久6| 日本视频一区二区三区| 午夜影院久久久| 亚洲成人免费av| 亚洲成人在线网站| 亚洲第一久久影院| 亚洲大片在线观看| 亚洲一区二区视频在线| 一区二区三区在线播放| 一区二区高清在线| 亚洲曰韩产成在线| 亚洲成av人片一区二区| 午夜一区二区三区在线观看| 亚洲成a人片在线观看中文| 亚洲国产欧美一区二区三区丁香婷| 一区二区三区高清| 亚洲一区二区三区激情| 亚洲午夜在线视频| 亚洲成av人影院| 日韩精品国产欧美| 日本亚洲视频在线| 国内偷窥港台综合视频在线播放| 毛片基地黄久久久久久天堂| 日本中文字幕一区二区有限公司| 免费看日韩a级影片| 久久国产人妖系列| 国产一区二区在线视频| 国产成人午夜电影网| 国产精品69毛片高清亚洲| 国产大陆亚洲精品国产| 国产91清纯白嫩初高中在线观看| 成人黄页毛片网站| 欧美一区1区三区3区公司| 红杏aⅴ成人免费视频| 国产视频久久| 91黄色免费看| 制服丝袜激情欧洲亚洲| 日韩欧美一级片| 久久久久高清精品| 1区2区3区国产精品| 亚洲va欧美va天堂v国产综合| 毛片av中文字幕一区二区| 国模少妇一区二区三区|