该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
'打开指定的服务器
sql = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=food;Password=123456;Data Source=192.168.1.251\sql2005,1413"
'sql = "Provider=SQLOLEDB.1;Persist Secexcelnamety formname=False;User ID=" & UID & ";password=" & PWD & ";Data Source=" & DS
conn.Open sql
'获取服务器下的所有数据库
sql = "select Name from SysDatabases order by Name"
rs.Open sql, conn, 1, 1
If rs.RecordCount <> 0 Then
For k = 1 To rs.RecordCount
Combo1.AddItem Trim(rs.Fields("name").Value)
rs.MoveNext
Next
rs.Close
Else
rs.Close
End If
If conn.State = 1 Then
conn.Close
End If
Private Sub Combo1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
sql = "Provider=SQLOLEDB.1;Persist Secexcelnamety formname=False;User ID=food;password=123456;Data Source=192.168.1.251\sql2005,1413;Initial Catalog=" & Combo1.Text & ""
conn.Open sql
'加载数据库下用户表
sql = "select Name from SysObjects Where XType='U'and status>=0 order by Name"
rs.Open sql, conn, 1, 1
If rs.RecordCount <> 0 Then
For k = 1 To rs.RecordCount
Combo2.AddItem Trim(rs.Fields("name").Value)
rs.MoveNext
Next
rs.Close
Else
rs.Close
End If
End Sub
代码就是这么多, 刚学VB时候做的、、、以前写的比较简单..