VB connection MySQL Database

Source: Internet
Author: User
Tags odbc connection

Of course the machine is equipped with MySQL database

Then download and install the MYSQL,ODBC driver

Need to join ADO ' menu "project", "reference" to find Microsoft ActiveX Data Object .... or simply find the ADO control and throw it on the form and delete it.


The code to connect to the database in VB:


Dim cn as New ADODB. ConnectionDim rs as New ADODB. Recordset ' definition database connection string variable Dim strcn As String ' Define database connection parameter Dim db_host As StringDim Db_user as StringDim Db_pass as StringDim  Db_data As String ' Define SQL statement variable Dim sql As String ' Initialize database connection variable db_host = ' localhost ' db_user = ' root ' usernamedb_pass = ' root ' ' User Passworddb_data = ' Radio ' database name ' MySQL ODBC connection number ' +------------+---------------------+---------------------------- ------+ ' | Name of the Participant | Default value | Description | ' +------------+------------------------------------------------------–+ ' | user | ODBC (on Windows) | MySQL Username | ' | Server | localhost | MySQL server Address | ' |                     Database | | Default Connection Database | ' | Option | 0 | Parameters to specify how the connection works | ' | Port | 3306 | Connection Port | ' |                     stmt | | A statement that can execute after connecting to the database |                     password | |       MySQL User Password            | ' |                     sockets | | (slightly) | ' +------------+---------------------+----------------------------------+ ' specific view official notes ' http://dev.mysql.com/doc/ REFMAN/5.0/EN/MYODBC-CONFIGURATION-CONNECTION-PARAMETERS.HTMLSTRCN = "Driver={mysql ODBC 3.51 DRIVER};" & _ "S Erver= "& Db_host &"; "& _" database= "& Db_data &"; "& _" uid= "& Db_user & Amp "; Pwd= "& Db_pass &"; "& _" Option=3;stmt=set NAMES GB2312 "' Stmt=set NAMES GB2312 ' This is the Set database encoding method ' Chinese Operation Department The system needs to be set to GB2312 ' So Chinese will not have a problem ' version number requires MySQL 4.1+ ' to connect to the database CN. Open STRCN ' Sets this property so that the RecordCount and AbsolutePage properties are available in the CN. CursorLocation = adUseClient ' interview table Table1sql = "Select Nicheng,xinqing from nichengandxinqing where uid= ' 1 '" Rs. Open SQL, Cndim Nicheng as StringDim xinqing as String ' Load user Nickname Nicheng = Rs. Fields (0) Label1.Caption = Nicheng ' load user mood phrase xinqing = Rs. Fields (1) label2.caption = Xinqing ' mouse placed in mood phrase hint phrase specific information Label2.tooltiptext = xinqing ' Load network picture IMAge1. Picture = LoadPicture ("http://hi.csdn.net/attachment/201201/5/8747069_1325751084ZiD4.jpg")


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.