MySQL __ Connectors and APIs Manual __ 5.6.7.1 Using Connector_ODBC with Visual Basic Using ADO, DAO and RDO
MySQL __ Connectors and APIs Manual __ 5.6.7.1 Using Connector_ODBC with Visual Basic Using ADO, DAO and RDO
SQL :: Connectors and APIs Manual :: 5.6.7.1 Using Connector/ODBC with Visual Basic Using ADO, DAO and RDO
Connectors and APIs Manual / MySQL Connector/ODBC Developer Guide / Connector/ODBC Examples / Connector/ODBC Programming / Using Connector/ODBC with Visual Basic
Using ADO, DAO and RDO
5.6.7.1 Using Connector/ODBC with Visual Basic Using ADO, DAO and RDO
This section contains simple examples of the use of Connector/ODBC with ADO, DAO and RDO.
The following ADO (ActiveX Data Objects) example creates a table my_ado and demonstrates the use of rs.addNew, rs.delete, and rs.update.
https://dev.mysql.com/doc/connectors/en/connector-odbc-examples-programming-vb.html 1/7
3/10/23, 10:02 MySQL :: Connectors and APIs Manual :: 5.6.7.1 Using Connector/ODBC with Visual Basic Using ADO, DAO and RDO
https://dev.mysql.com/doc/connectors/en/connector-odbc-examples-programming-vb.html 2/7
3/10/23, 10:02 MySQL :: Connectors and APIs Manual :: 5.6.7.1 Using Connector/ODBC with Visual Basic Using ADO, DAO and RDO
rs.Update
rs.Close
'rs delete
rs.Open "SELECT * FROM my_ado"
rs.MoveNext
rs.MoveNext
rs.Delete
rs.Close
'fetch the updated table ..
rs.Open "SELECT * FROM my_ado", conn
Debug.Print rs.RecordCount
rs.MoveFirst
Debug.Print String(50, "-") & "Updated my_ado Result Set " & String(50, "-")
For Each fld In rs.Fields
Debug.Print fld.Name,
Next
Debug.Print
Do Until rs.EOF
For Each fld In rs.Fields
Debug.Print fld.Value,
Next
rs.MoveNext
Debug.Print
Loop
rs.Close
conn.Close
End Sub
The following DAO (Data Access Objects) example creates a table my_dao and demonstrates the use of rs.addNew, rs.update, and result set scrolling.
https://dev.mysql.com/doc/connectors/en/connector-odbc-examples-programming-vb.html 3/7
3/10/23, 10:02 MySQL :: Connectors and APIs Manual :: 5.6.7.1 Using Connector/ODBC with Visual Basic Using ADO, DAO and RDO
https://dev.mysql.com/doc/connectors/en/connector-odbc-examples-programming-vb.html 4/7
3/10/23, 10:02 MySQL :: Connectors and APIs Manual :: 5.6.7.1 Using Connector/ODBC with Visual Basic Using ADO, DAO and RDO
The following RDO (Remote Data Objects) example creates a table my_rdo and demonstrates the use of rs.addNew and rs.update.
Dim rs As rdoResultset
Dim cn As New rdoConnection
https://dev.mysql.com/doc/connectors/en/connector-odbc-examples-programming-vb.html 5/7
3/10/23, 10:02 MySQL :: Connectors and APIs Manual :: 5.6.7.1 Using Connector/ODBC with Visual Basic Using ADO, DAO and RDO
Dim cl As rdoColumn
Dim SQL As String
'cn.Connect = "DSN=test;"
cn.Connect = "DRIVER={MySQL ODBC 3.51 Driver};"_
& "SERVER=localhost;"_
& " DATABASE=test;"_
& "UID=venu;PWD=venu; OPTION=3"
cn.CursorDriver = rdUseOdbc
cn.EstablishConnection rdDriverPrompt
'drop table my_rdo
SQL = "drop table if exists my_rdo"
cn.Execute SQL, rdExecDirect
'create table my_rdo
SQL = "create table my_rdo(id int, name varchar(20))"
cn.Execute SQL, rdExecDirect
'insert - direct
SQL = "insert into my_rdo values (100,'venu')"
cn.Execute SQL, rdExecDirect
SQL = "insert into my_rdo values (200,'MySQL')"
cn.Execute SQL, rdExecDirect
'rs insert
SQL = "select * from my_rdo"
Set rs = cn.OpenResultset(SQL, rdOpenStatic, rdConcurRowVer, rdExecDirect)
rs.AddNew
rs!id = 300
rs!Name = "Insert1"
rs.Update
rs.Close
'rs insert
SQL = "select * from my_rdo"
Set rs = cn.OpenResultset(SQL, rdOpenStatic, rdConcurRowVer, rdExecDirect)
rs.AddNew
rs!id = 400
rs!Name = "Insert 2"
rs.Update
https://dev.mysql.com/doc/connectors/en/connector-odbc-examples-programming-vb.html 6/7
3/10/23, 10:02 MySQL :: Connectors and APIs Manual :: 5.6.7.1 Using Connector/ODBC with Visual Basic Using ADO, DAO and RDO
rs.Close
'rs update
SQL = "select * from my_rdo"
Set rs = cn.OpenResultset(SQL, rdOpenStatic, rdConcurRowVer, rdExecDirect)
rs.Edit
rs!id = 999
rs!Name = "updated"
rs.Update
rs.Close
'fetch back...
SQL = "select * from my_rdo"
Set rs = cn.OpenResultset(SQL, rdOpenStatic, rdConcurRowVer, rdExecDirect)
Do Until rs.EOF
For Each cl In rs.rdoColumns
Debug.Print cl.Value,
Next
rs.MoveNext
Debug.Print
Loop
Debug.Print "Row count="; rs.RowCount
'close
rs.Close
cn.Close
End Sub
© 2023 Oracle
https://dev.mysql.com/doc/connectors/en/connector-odbc-examples-programming-vb.html 7/7