vb连接mysql数据库后怎么获取数据

2024-12-16 14:39:24
推荐回答(1个)
回答1:

Option Explicit

'工程->引用->Microsoft ActiveX Data Object 2.0 Library (后面为版本号)
Dim cn As New ADODB.Connection

Private Sub Command1_Click()
Dim rs As New ADODB.Recordset

rs.Open "select * from astuff", cn, adOpenDynamic, adLockOptimistic
rs.Close
Set rs = Nothing
End Sub

Private Sub Form_Load()
On Error GoTo Errhandle
cn.ConnectionString = "Driver={MySQL};Option=0;port=;stmt=;Server=orient-xxl;DataBase=orientnbcws;User=root;Password="
cn.Open

Exit Sub
Errhandle:
MsgBox Err.Description, vbExclamation
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
cn.Close
Set cn = Nothing
End Sub