How to connect mysql database using vb6

Dim DBCon As ADODB.Connection
Dim Cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim strName As String

‘Create a connection to the database
Set DBCon = New ADODB.Connection
DBCon.CursorLocation = adUseClient
‘This is a connectionstring to a local MySQL server
DBCon.Open “DRIVER={MySQL ODBC 3.51 Driver};Server=;Database=emarketi_smsdb; User=emarketi_smsdb;Password=;Option=3;”

‘Create a new command that will execute the query
Set Cmd = New ADODB.Command
Cmd.ActiveConnection = DBCon
Cmd.CommandType = adCmdText
‘This is your actual MySQL query
Cmd.CommandText = “SELECT * FROM sms_log”

‘Executes the query-command and puts the result into Rs (recordset)
Set rs = Cmd.Execute

‘Loop through the results of your recordset until there are no more records
Do While Not rs.EOF
‘Put the value of field ‘Name’ into string variable ‘Name’
strName = rs(“sms”)
MsgBox strName

‘Move to the next record in your resultset
rs.MoveNext

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s