欧美成人精品手机在线观看_69视频国产_动漫精品第一页_日韩中文字幕网 - 日本欧美一区二区

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開(kāi)發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

怎樣在VB中實(shí)現(xiàn)附加分離數(shù)據(jù)庫(kù)

admin
2014年3月25日 1:14 本文熱度 5847
'創(chuàng)建連接
    Dim strcon As String = "integrated security=sspi;server=(local);database=master"
    Dim mycon As New SqlConnection(strcon)

1附加數(shù)據(jù)庫(kù)
Dim mycmd2 As New SqlCommand
        mycmd2.Connection = mycon搜索
        mycmd2.CommandType = CommandType.Text
        mycmd2.CommandText = "select * from sysdatabases"
        '打開(kāi)連接
        mycon.Open()
        '執(zhí)行數(shù)據(jù)命令并綁定控件
        Dim myreader As SqlDataReader
        myreader = mycmd2.ExecuteReader
        If myreader.HasRows Then
            While myreader.Read()
                If Me.TextBox1.Text = myreader(0) Then
                    MessageBox.Show("很抱歉!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
                    Exit Sub
                End If
            End While
        End If
        mycon.Close()
        Dim filepath1 As String = ""
        OpenFileDialog1.Filter = "mdf文件|*.mdf"
        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            filepath1 = OpenFileDialog1.FileName
        End If
        '創(chuàng)建數(shù)據(jù)命令
        Dim mycmd As New SqlCommand
        mycmd.Connection = mycon
        mycmd.CommandType = CommandType.StoredProcedure
        mycmd.CommandText = "sp_attach_db"
        '加入?yún)?shù)
        Dim name As SqlParameter = mycmd.Parameters.Add("@dbname", SqlDbType.NVarChar)
        Dim filename1 As SqlParameter = mycmd.Parameters.Add("@filename1", SqlDbType.NVarChar)
        Dim filename2 As SqlParameter = mycmd.Parameters.Add("@filename2", SqlDbType.NVarChar)
        '設(shè)置參數(shù)屬性
        name.Direction = ParameterDirection.Input
        '給參數(shù)賦值
        name.Value = Trim(Me.TextBox1.Text)
        filename1.Value = Me.OpenFileDialog1.FileName.Replace(".mdf", ".ldf")
        filename2.Value = Me.OpenFileDialog1.FileName
        '打開(kāi)連接
        mycon.Open()
        '執(zhí)行數(shù)據(jù)命令
        Try
            mycmd.ExecuteNonQuery()
            MsgBox("數(shù)據(jù)庫(kù)附加成功!")
            Me.ComboBox1.Items.Add(Trim(Me.TextBox1.Text))
            Me.TextBox1.Text = ""
        Catch ex As Exception
            MessageBox.Show(ex.Message, "請(qǐng)注意!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        Finally
            '關(guān)閉連接
            mycon.Close()
        End Try

2/分離數(shù)據(jù)庫(kù)

If Me.ComboBox1.SelectedItem = "master" Or Me.ComboBox1.SelectedItem = "model" Or Me.ComboBox1.SelectedItem = "msdb" Or Me.ComboBox1.SelectedItem = "Northwind" Or Me.ComboBox1.SelectedItem = "pubs" Or Me.ComboBox1.SelectedItem = "tempdb" Then
            MessageBox.Show("很抱歉,你無(wú)權(quán)分離系統(tǒng)數(shù)據(jù)庫(kù)!")
            Exit Sub
        End If

        '創(chuàng)建數(shù)據(jù)命令
        Dim mycmd As New SqlCommand
        mycmd.Connection = mycon
        mycmd.CommandType = CommandType.StoredProcedure
        mycmd.CommandText = "sp_detach_db"
        '加入?yún)?shù)
        Dim name As SqlParameter = mycmd.Parameters.Add("@dbname", SqlDbType.NVarChar)

        '設(shè)置參數(shù)屬性
        name.Direction = ParameterDirection.Input
        '給參數(shù)賦值
        name.Value = Trim(Me.ComboBox1.SelectedItem)
        '打開(kāi)連接
        mycon.Open()
        '執(zhí)行數(shù)據(jù)命令
        Try
            mycmd.ExecuteNonQuery()
            MsgBox("數(shù)據(jù)庫(kù)分離成功!")
            Me.ComboBox1.Items.Remove(Trim(Me.ComboBox1.SelectedItem))
        Catch ex As Exception
            MessageBox.Show(ex.Message, "請(qǐng)注意!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        Finally
            '關(guān)閉連接
            mycon.Close()
        End Try

    End Sub

    Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ComboBox1.Text = ""
        Dim mycmd1 As New SqlCommand
        mycmd1.Connection = mycon
        mycmd1.CommandType = CommandType.Text
        mycmd1.CommandText = "select * from sysdatabases"
        '打開(kāi)連接
        mycon.Open()
        '執(zhí)行數(shù)據(jù)命令并綁定控件
        Dim myreader As SqlDataReader
        myreader = mycmd1.ExecuteReader
        If myreader.HasRows Then
            While myreader.Read()
                Me.ComboBox1.Items.Add(myreader(0))
            End While
        End If
        mycon.Close()
    End Sub

該文章在 2014/3/25 1:14:35 編輯過(guò)
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國(guó)內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車(chē)隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開(kāi)發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類(lèi)企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉(cāng)儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷(xiāo)售管理,采購(gòu)管理,倉(cāng)儲(chǔ)管理,倉(cāng)庫(kù)管理,保質(zhì)期管理,貨位管理,庫(kù)位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved