Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-04-2009
Member
 
Join Date: Feb 2009
Posts: 43
Mysql In Visual Basic 6.0

hi,
I would like to know how to connect the MySQL databse with visual basic?what is the simple code that connect visual basic and Mysql.Any recommendations and suggestions are appreciated.
Reply With Quote
  #2  
Old 14-04-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Mysql In Visual Basic 6.0

You need to download MyVbQL project, from Planet Source Code, and compile it into a dll, or include it directly in your project, and easily use it as a class...

Library has 4 classes: MYSQL_CONNECTION -> Provides connectivity to MySQL server MYSQL_RS -> Provides access to recordsets(tables) within MySQL database MYSQL_FIELD -> Provides access to fields within MySQL table MYSQL_ERR -> Provides access to error object, to see if any MySQL errors occured You can access tables fields same as you would access a variable declared as a Collection: Recordset.Fields("fieldname").Value Recordset.Fields(fieldindex).Value As the library is open source, when you get the source code, you will see all the properties of all four classes in the project... I'd recommend downloading it from PSC.
Reply With Quote
  #3  
Old 14-04-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Mysql In Visual Basic 6.0

have you installed odbc driver 3.51. if not then download and install it. Then create a DSN from control panel-> administrartive tools -> data sources (ODBC). And then paste below code:

Code:
Dim sqlstr As String 
Dim rs As ADODB.Recordset 
Dim conn As ADODB.Connection 
conn = New ADODB.Connection 
rs = New ADODB.Recordset 
conn.Open("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=urdatabasename;USER=ABC;PASSWORD=XYZ;OPTION=3;") 
sqlstr = "select * from test_table" 
rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient 
rs.Open(sqlstr, conn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic) 
MsgBox("success" & rs.RecordCount)
Reply With Quote
  #4  
Old 14-04-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Mysql In Visual Basic 6.0

use this:
Code:
dim con1 as new adodb.connection
con1.CursorLocation = adUseClient
con1.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=serverip;DATABASE=databasename;USER=usename;PASSWORD=pwd;;;"
con1.Open
then suppose u have table emp in ur dbase
then 
dim k as new adodb.recordset
set k=new adodb.recordset
k.open "select * from emp",con1,adopendynamic,adlockoptimistic
use k recordset as you want,first set connection in odbc in control panel
Reply With Quote
  #5  
Old 14-04-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Mysql In Visual Basic 6.0

hi,
you must have the driver that is used in connecting to mysql.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Mysql In Visual Basic 6.0"
Thread Thread Starter Forum Replies Last Post
what are Visual Basic IDE? Naresh Modi Software Development 2 06-03-2009 09:49 AM
Is GUI same like Visual Basic ? Caesar Software Development 2 02-03-2009 01:32 PM
Visual Basic 2005 or Visual Basic 6 Aasha Software Development 5 15-01-2009 06:56 PM
Light remote visual fox pro to MySQL 5 Vincenzo Software Development 1 10-10-2008 07:03 PM
Visual Basic on LAN djbbenn Software Development 2 05-08-2008 02:15 PM


All times are GMT +5.5. The time now is 11:21 PM.