本文目录一览:
vb如何连接操作MYSQL数据库
必须安装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
vb6.0如何连接MYSQL数据库?
最简单的办法是:在VB里添加一个ADO部件,将其放到窗体中,然后右键选择属性,在其属性页的下面有个生成连接字符串的项,点击其后的按钮,然后一步步的来做(很简单的),然后连接字符串就会在那里生成,只要拷贝这个字符串,就可以用ADODB来连接了。。。
我想用vb操作mysql数据库,可行否
可以的,这个没有问题。
参考:
Option Strict On
Imports MySql.Data.MySqlClient
Module Example
Sub Main()
Dim cs As String = "Database=testdb;Data Source=localhost;" _
"User Id=testuser;Password=test623"
Dim conn As New MySqlConnection(cs)
Try
conn.Open()
Console.WriteLine("MySQL version : {0}", conn.ServerVersion)
Catch ex As MySqlException
Console.WriteLine("Error: " ex.ToString())
Finally
conn.Close()
End Try
End Sub
End Module
vb如何连接操作MYSQL数据库啊
必须安装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