dim conn as new adodb.connection
dim rec as new adodb.recordset
dim sSQL as string
conn.open "数据库连接串"
sSQL = "select a from aa" '从aa表中查询a字段
rec.CursorLocation = adUseClient
rec.Open sSQL, conn, adOpenForwardOnly, adLockReadOnly
If rec.RecordCount > 0 Then
rec.MoveFirst
MsgBox rec("a") '获取第一行的a字段值
End If
为了节约资源,楼上的代码最后加一个rec.close
如果你要修改内容,
rec.open ssql,conn,adopenkeyset,adlockoption
rec("a")= ???然后,rec.update
还有,我经常把conn写在模块里,大家共用一个连接,省和老是去连数据库。