下面是利用SQL語句創建數據庫
以下是引用片段
Imports System
Imports System
Public Class Form
Inherits System
Private ConnectionString As String =
Private reader As SqlDataReader = Nothing
Private conn As SqlConnection = Nothing
Private cmd As SqlCommand = Nothing
Private AlterTableBtn As System
Private sql As String = Nothing
Private CreateOthersBtn As System
#Region
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components
End If
End If
MyBase
End Sub
Public Sub New()
MyBase
InitializeComponent()
End Sub
Private components As System
Friend WithEvents DataGrid
Friend WithEvents CreateDBBtn As System
Friend WithEvents CreateTableBtn As System
Friend WithEvents CreateSPBtn As System
Friend WithEvents CreateViewBtn As System
Friend WithEvents btnAlterTable As System
Friend WithEvents btnCreateOthers As System
Friend WithEvents btnDropTable As System
Friend WithEvents btnViewData As System
Friend WithEvents btnViewSP As System
Friend WithEvents btnViewView As System
<System
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
CType(Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
Me
CType(Me
Me
End Sub
#End Region
Private Sub CreateDBBtn_Click(ByVal sender As System
Handles CreateDBBtn
conn = New SqlConnection(ConnectionString)
If conn
conn
End If
Dim sql As String =
cmd = New SqlCommand(sql
Try
cmd
Catch ae As SqlException
MessageBox
End Try
End Sub
Private Sub CreateTableBtn_Click(ByVal sender As System
Handles CreateTableBtn
conn = New SqlConnection(ConnectionString)
If conn
conn
End If
ConnectionString =
conn
conn
sql =
cmd = New SqlCommand(sql
Try
cmd
sql =
cmd = New SqlCommand(sql
cmd
sql =
cmd = New SqlCommand(sql
cmd
sql =
cmd = New SqlCommand(sql
cmd
sql =
cmd = New SqlCommand(sql
cmd
Catch ae As SqlException
MessageBox
End Try
End Sub
Private Sub CreateSPBtn_Click(ByVal sender As System
Handles CreateSPBtn
sql =
ExecuteSQLStmt(sql)
End Sub
Private Sub CreateViewBtn_Click(ByVal sender As System
Handles CreateViewBtn
sql =
ExecuteSQLStmt(sql)
End Sub
Private Sub btnAlterTable_Click(ByVal sender As System
Handles btnAlterTable
sql =
ExecuteSQLStmt(sql)
End Sub
Private Sub btnCreateOthers_Click(ByVal sender As System
Handles btnCreateOthers
sql =
ExecuteSQLStmt(sql)
sql =
ExecuteSQLStmt(sql)
End Sub
Private Sub btnDropTable_Click(ByVal sender As System
Handles btnDropTable
Dim sql As String =
ExecuteSQLStmt(sql)
End Sub
Private Sub btnViewData_Click(ByVal sender As System
Handles btnViewData
conn = New SqlConnection(ConnectionString)
If conn
conn
End If
ConnectionString =
conn
conn
Dim da As New SqlDataAdapter(
Dim ds As New DataSet(
da
DataGrid
End Sub
Private Sub btnViewSP_Click(ByVal sender As System
Handles btnViewSP
conn = New SqlConnection(ConnectionString)
If conn
conn
End If
ConnectionString =
conn
conn
Dim da As New SqlDataAdapter(
Dim ds As New DataSet(
da
DataGrid
End Sub
Private Sub btnViewView_Click(ByVal sender As System
Handles btnViewView
conn = New SqlConnection(ConnectionString)
If conn
conn
End If
ConnectionString =
conn
conn
Dim da As New SqlDataAdapter(
Dim ds As New DataSet()
da
DataGrid
End Sub
Private Sub ExecuteSQLStmt(ByVal sql As String)
conn = New SqlConnection(ConnectionString)
If conn
conn
End If
ConnectionString =
conn
conn
cmd = New SqlCommand(sql
Try
cmd
Catch ae As SqlException
MessageBox
End Try
End Sub
End Class
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22212.html