一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

VB附加SQL 数据库

时间:2008-04-26 编辑:简简单单 来源:一聚教程网

效果图:

                        

代码如下:

Public m As String, l As String, strdata As String
Private Sub Command1_Click()
  Dim cn As New ADODB.Connection
  On Error GoTo dataErr
  cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=zhan;User ID=sa;password=zhan;Initial Catalog=master"
1  cn.Execute ("sp_attach_db @dbname =''" & strdata & "'', @filename1 = N" & "''" & m & "'', @filename2 = N" & "''" & l & "''")
  MsgBox "附加成功!", , "VB附加数据库"
  Exit Sub
dataErr:
  MsgBox Err.Description, , "VB附加数据库"
End Sub
Private Sub Command2_Click()
  With CommonDialog1
     .InitDir = "E:ASP光盘修改文件mrfl"
     .ShowOpen
     If .FileName <> "" Then
        Text1 = .FileName
        m = .FileName
        l = Mid(.FileName, 1, Len(.FileName) - 8) & "Log.LDF"
        strdata = Mid(.FileTitle, 1, Len(.FileTitle) - 9)
        If List1.ListCount > 0 Then
          List1.Clear
   &nbs

<