欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

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

程序员文章站 2024-02-15 22:18:11
...
 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) "
相关标签: 数据库表 动态