module1.bas

来自「办公自动化系统--vb+access」· BAS 代码 · 共 35 行

BAS
35
字号
Attribute VB_Name = "Module1"
Public PublicStr As String
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Str As String
Dim Server As String
Dim uid As String
Dim pwd As String
Public Sub main()
  '读取数据库配置文件
  Open (App.Path & "\DataBase.ini") For Input As #1
        Line Input #1, Intext
        Server = Mid(Intext, 10, Len(Trim(Intext)) - 9)
        Line Input #1, Intext
        uid = Mid(Intext, 7, Len(Trim(Intext)) - 6)
        Line Input #1, Intext
        pwd = Mid(Intext, 7, Len(Trim(Intext)) - 6)
  Close #1

'附加数据库
  On Error Resume Next
  con.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & uid & ";PWD=" & pwd & ";"
  con.Open     '打开数据库连接
  Set rs = New ADODB.Recordset
  '开始附加数据库
  Str = "EXEC sp_attach_db @dbname = N'db_OA', @filename1 = N'" + App.Path + "\DataBase\db_OA_Data.MDF" + "', @filename2 = N'" + App.Path + "\DataBase\db_OA_Log.LDF" + "'"
'  rs.Open str, con, 1, adLockOptimistic
  Set rs = con.Execute(Str)
  con.Close  '关闭数据库连接
  '共享连接字符串
  PublicStr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & uid & ";PWD=" & pwd & ";Initial Catalog=db_OA;Data Source=" & Server & ""
  frm_login.Show
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?