vb测试连接数据库
答案:2 悬赏:40 手机版
解决时间 2021-02-22 10:17
- 提问者网友:原来太熟悉了会陌生
- 2021-02-21 19:49
我现在做一个数据库连接,但我不知道怎么测试数据库通不通,我想通过一个按扭实现提示数据测试成功
最佳答案
- 五星知识达人网友:野慌
- 2021-02-21 20:21
Option Explicit
Dim conn As ADODB.Connection
Private Sub Command1_Click()
On Error Resume Next
conn.Open
MsgBox conn.State
End Sub
Private Sub Form_Load()
Set conn = New ADODB.Connection
conn.CursorLocation = adUseClient
conn.ConnectionString = ""
End Sub
如果conn.state 返回值为0,数据库连接失败,为1连接成功
Dim conn As ADODB.Connection
Private Sub Command1_Click()
On Error Resume Next
conn.Open
MsgBox conn.State
End Sub
Private Sub Form_Load()
Set conn = New ADODB.Connection
conn.CursorLocation = adUseClient
conn.ConnectionString = ""
End Sub
如果conn.state 返回值为0,数据库连接失败,为1连接成功
全部回答
- 1楼网友:鸠书
- 2021-02-21 21:58
private conn as new adodb.connection private rs as new adodb.recordset
private sub form_load() dim datapath as string datapath = "c:\data.mdb" '数据库路径 if dir("datapath") <> "" then conn.open "provider=microsoft.jet.oledb.4.0;data source=" & datapath & ";mode=readwrite|share deny none;persist security info=false" else msgbox "数据库存在", , "提示"
end if end sub
'以上是access数据库连接方式
'你要在什么控件显示上什么东西呢???
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯