大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
最简单的办法是:在VB里添加一个ADO部件,将其放到窗体中,然后右键选择属性,在其属性页的下面有个生成连接字符串的项,点击其后的按钮,然后一步步的来做(很简单的),然后连接字符串就会在那里生成,只要拷贝这个字符串,就可以用ADODB来连接了。。。
成都创新互联公司基于成都重庆香港及美国等地区分布式IDC机房数据中心构建的电信大带宽,联通大带宽,移动大带宽,多线BGP大带宽租用,是为众多客户提供专业服务器托管报价,主机托管价格性价比高,为金融证券行业达州服务器托管,ai人工智能服务器托管提供bgp线路100M独享,G口带宽及机柜租用的专业成都idc公司。
楼上讲的是VB2005的连接方法,不知道你用的是什么版本的VB,我给你一个VB6.0的连接方法吧
先在本机上安装最新的ODBC CONNECTER/mysql
无需设置ODBC,就可以使用.
注意MYSQL的帐户登录是根据主机的,设置好MYSQL的帐户后再做测试.
测试代码:
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim fld As ADODB.Field
Dim sql As String
'connect to MySQL server using MySQL ODBC 3.51 Driver
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
"SERVER=192.168.0.1;" _
" DATABASE=db_name;" _
"UID=username;PWD=password; OPTION=3"
conn.Open
'create table
conn.Execute "DROP TABLE IF EXISTS my_ado"
conn.Execute "CREATE TABLE my_ado(id int not null primary key, name varchar(20)," _
"txt text, dt date, tm time, ts timestamp)"
'direct insert
conn.Execute "INSERT INTO my_ado(id,name,txt) values(1,100,'venu')"
conn.Execute "INSERT INTO my_ado(id,name,txt) values(2,200,'MySQL')"
conn.Execute "INSERT INTO my_ado(id,name,txt) values(3,300,'Delete')"
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
'fetch the initial table ..
rs.Open "SELECT * FROM my_ado", conn
Debug.Print rs.RecordCount
rs.MoveFirst
Debug.Print String(50, "-") "Initial my_ado Result Set " String(50, "-")
For Each fld In rs.Fields
Debug.Print fld.name,
Next
Debug.Print
Do Until rs.EOF
For Each fld In rs.Fields
Debug.Print fld.value,
Next
rs.MoveNext
Debug.Print
Loop
rs.Close
conn.Close
用mysql odbc connector,然后建立数据源,vb里用SqlDataResouce空控件置dsn连就可以了~
用如下语句即可
dim con
set con=createobject("ADODB.Connection")
con.open "driver={sql server};Driver={sql server};uid=用户名;pwd=用户密码;database=数据库名称;server=(local)"
con.execute("你想执行的SQL语句")