当前位置:Gxlcms > mysql > 教你创建动态MSSQL数据库表(4)_MySQL

教你创建动态MSSQL数据库表(4)_MySQL

时间:2021-07-01 10:21:17 帮助过:33人阅读

 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) "

人气教程排行