教你创建动态MQL 数据库表(4)_MySQL数据库_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

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

作者:黑客防线网安MYSQL维护基地 来源:黑客防线网安MYSQL维护基地 浏览次数:0

本篇关键词:数据库动态创建
黑客防线网安网讯: Me.CreateViewBtn, Me.CreateSPBtn, Me.CreateTableBtn, Me.CreateDBBtn})   Me.Name = "Form1"   Me.Text = "动态创建SQL Server数据库、表、存储过程等架构信息"   CType(Me.Data...
 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) "
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-8688-1.html
网站维护教程更新时间:2012-03-20 04:59:32  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer