vb如何连接操作MYSQL数据库啊
2个回答
展开全部
必须安装mysql的驱动才行,不管是vb还是c++都需要这个驱动。
代码如下:
public
function
exemysql(byval
sql
as
string)
as
adodb.recordset
sql
=
trim$(sql)
set
conn
=
new
adodb.connection
set
rs
=
new
adodb.recordset
conn.open
"driver=mysql
odbc
3.51
driver;"
&
_
"server=服务器地址;"
&
_
"port=3306;"
&
_
"database=数据库名;"
&
_
"uid=用户名;"
&
_
"pwd=密码"
conn.defaultdatabase
=
"数据库名"
conn.cursorlocation
=
aduseclient
set
rs.activeconnection
=
conn
rs.locktype
=
adlockbatchoptimistic
rs.cursortype
=
adopenkeyset
rs.open
sql
set
exesql
=
rs
set
rs
=
nothing
set
conn
=
nothing
end
function
代码如下:
public
function
exemysql(byval
sql
as
string)
as
adodb.recordset
sql
=
trim$(sql)
set
conn
=
new
adodb.connection
set
rs
=
new
adodb.recordset
conn.open
"driver=mysql
odbc
3.51
driver;"
&
_
"server=服务器地址;"
&
_
"port=3306;"
&
_
"database=数据库名;"
&
_
"uid=用户名;"
&
_
"pwd=密码"
conn.defaultdatabase
=
"数据库名"
conn.cursorlocation
=
aduseclient
set
rs.activeconnection
=
conn
rs.locktype
=
adlockbatchoptimistic
rs.cursortype
=
adopenkeyset
rs.open
sql
set
exesql
=
rs
set
rs
=
nothing
set
conn
=
nothing
end
function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询