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.
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.
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.
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)
use this:
use k recordset as you want,first set connection in odbc in control panelCode: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
hi,
you must have the driver that is used in connecting to mysql.
Bookmarks