vb的ADO控件如何连接操作MYSQL数据库啊
2个回答
2013-06-11
展开全部
这要看你是用控件Adodc 还是用面向对象的编程adodb,如果是你只是临时的做一点东西,那么建议你用adodc!这是可视化的直接从部件里面调出来就是了!在设置一下它的属性就可以链接SQL了。建议你用adodb,这样你才会真正的体会面向对象编程的精髓。可以参考上面那么仁兄的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-11
展开全部
看这么长时间没人回答,我就帮你写一个吧
'创建连接 ,DateBaseName是数据库路径,DateUserID, DatePassword是用户名和密码
Set objConn = DbConnection("MSACCESS", DateBaseName, DateUserID, DatePassword)
'放到模块里面,DbConnection连接数据库函数
Public Function DbConnection(strDatabaseType As String, strDBService As String, Optional strUserID As String, Optional strPassword As String) As adodb.Connection
Dim objDB As New adodb.Connection
Dim strConnectionString As String
'定义Access数据库连接字符串
strConnectionString = "DBQ=" & strDBService
strConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; " & strConnectionString
With objDB
.Mode = adModeReadWrite ' 连接模式
.ConnectionTimeout = 10
.CommandTimeout = 5
.CursorLocation = adUseClient
.Open strConnectionString, strUserID, strPassword
End With
Set DbConnection = objDB
End Function
'创建连接 ,DateBaseName是数据库路径,DateUserID, DatePassword是用户名和密码
Set objConn = DbConnection("MSACCESS", DateBaseName, DateUserID, DatePassword)
'放到模块里面,DbConnection连接数据库函数
Public Function DbConnection(strDatabaseType As String, strDBService As String, Optional strUserID As String, Optional strPassword As String) As adodb.Connection
Dim objDB As New adodb.Connection
Dim strConnectionString As String
'定义Access数据库连接字符串
strConnectionString = "DBQ=" & strDBService
strConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; " & strConnectionString
With objDB
.Mode = adModeReadWrite ' 连接模式
.ConnectionTimeout = 10
.CommandTimeout = 5
.CursorLocation = adUseClient
.Open strConnectionString, strUserID, strPassword
End With
Set DbConnection = objDB
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询