当然机器装有mysql数据库
然后下载安装Mysql,odbc驱动
须要加入ado‘菜单"project"->"引用" 找 Microsoft ActiveX Data Object.... 或者简单点找到ado控件 扔到窗体上 再删除 也行
在vb中连接数据库的代码:
Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset ‘ 定义数据库连接字符串变量 Dim strCn As String ‘ 定义数据库连接參数变量 Dim db_host As String Dim db_user As String Dim db_pass As String Dim db_data As String ‘ 定义 SQL 语句变量 Dim sql As String ‘ 初始化数据库连接变量 db_host = "localhost" db_user = "root" ‘username db_pass = "root" ’用户password db_data = "radio" ‘数据库名 ‘ MySQL ODBC 连接參数 ‘+------------+---------------------+----------------------------------+ ‘| 參数名 | 默认值 | 说明 | ‘+------------+------------------------------------------------------–+ ‘| user | ODBC (on Windows) | MySQL username | ‘| server | localhost | MySQL 服务器地址 | ‘| database | | 默认连接数据库 | ‘| option | 0 | 參数用以指定连接的工作方式 | ‘| port | 3306 | 连接端口 | ‘| stmt | | 一段声明, 能够在连接数据库后执行 | ‘| password | | MySQL 用户密码 | ‘| socket | | (略) | ‘+------------+---------------------+----------------------------------+ ‘ 具体查看官方说明 ‘ http://dev.mysql.com/doc/refman/5.0/en/myodbc-configuration-connection-parameters.html strCn = "DRIVER={MySQL ODBC 3.51 Driver};" & _ "SERVER=" & db_host & ";" & _ "DATABASE=" & db_data & ";" & _ "UID=" & db_user & ";PWD=" & db_pass & ";" & _ "OPTION=3;stmt=SET NAMES GB2312" ‘ stmt=SET NAMES GB2312 ‘ 这句是设置数据库编码方式 ‘ 中文操作系统须要设置成 GB2312 ‘ 这样中文才不会有问题 ‘ 版本号要求 mysql 4.1+ ‘ 连接数据库 cn.Open strCn ‘ 设置该属性, 使 recordcount 和 absolutepage 属性可用 cn.CursorLocation = adUseClient ‘ 訪问表 table1 sql = "select nicheng,xinqing from nichengandxinqing where uid=‘1‘" rs.Open sql, cn Dim nicheng As String Dim xinqing As String ‘载入用户昵称 nicheng = rs.Fields(0) Label1.Caption = nicheng ‘载入用户心情短语 xinqing = rs.Fields(1) Label2.Caption = xinqing ‘鼠标放在心情短语提示短语具体信息 Label2.ToolTipText = xinqing ‘载入网络图片 Image1.Picture = LoadPicture("http://hi.csdn.net/attachment/201201/5/8747069_1325751084ZiD4.jpg")