- In the click event of the btnOpenRecordset button, add the code to open a recordset.
Private Sub btnOpenRecordset_Click(sender As Object, e As EventArgs) Handles btnOpenRecordset.Click
On Error GoTo Errorhandler
Dim oConnection As ADODB.Connection
Dim oRst As ADODB.Recordset
Dim sConnectionString As String
Dim sSQL As String
oConnection = New ADODB.Connection
oRst = New ADODB.Recordset
sConnectionString = "Provider=MSOLEDBSQL;Server=
;Database=DatabaseName;User ID=;Password=
"
oConnection.Open(sConnectionString)
oRst.Open(sSQL, oConnection)
Msgbox(oRst.Fields("").Value.ToString)
oRst.Close
oConnection.Close
oRst = Nothing
oConnection = Nothing
Exit Sub
Errorhandler:
Msgbox(Err.Number & "-" & Err.Source & ": " & Err.Description)
End Sub