首页 > 代码库 > VB连接Mysql数据库

VB连接Mysql数据库

当然机器装有mysql数据库

然后下载安装Mysql,odbc驱动

须要加入ado‘菜单"project"->"引用" 找 Microsoft ActiveX Data Object.... 或者简单点找到ado控件 扔到窗体上 再删除 也行


 

在vb中连接数据库的代码:


Dim cn As New ADODB.ConnectionDim rs As New ADODB.Recordset‘ 定义数据库连接字符串变量Dim strCn As String‘ 定义数据库连接參数变量Dim db_host As StringDim db_user As StringDim db_pass As StringDim db_data As String‘ 定义 SQL 语句变量Dim sql As String‘ 初始化数据库连接变量db_host = "localhost"db_user = "root" ‘usernamedb_pass = "root" ’用户passworddb_data = http://www.mamicode.com/"radio" ‘数据库名>