dim con As New ADODB.Connection
dim connstrf1 As String
dim rs As New ADODB.Recordset
If rs.State = adStateOpen Then rs.Close
If con.State = adStateOpen Then con.Close
connstrf1 = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=数据库;Data Source=IP,1433(端口)"
con.ConnectionString = connstrf1
con.Open
con.CursorLocation = adUseClient
rs.Open "select ID,用户名,状态 from 表名 ordeR by ID", con, , adLockOptimistic
ListBox1.Clear
Do While Not rs.EOF
ListBox1.AddItem (rs.Fields("用户名"))
rs.MoveNext
Loop
(此代码放在平台为本人为方便日后查阅,同时也欢迎大家分享)