猿问

VB连接DB数据库?

VB连接DB数据库

数据库连接:
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data" & ";Mode=ReadWrite|Share Deny None;Persist Security Info=False;Jet OLEDB:Engine Type=82"
ConSql.ConnectionString = strConn
ConSql.Open

……

打开数据库:
sql = "select * from data"
rs.Open sql, ConSql, adOpenStatic, adLockReadOnly

这时,如果data.db被别的打开时,VB打开时就会出现:“无法锁定数据表data;正被机器 '(未知)' 上的用户 '(未知)' 使用。”

请问这如何解决?

慕哥6287543
浏览 1128回答 1
1回答

慕森卡

'记得引用Microsoft Active....2.6/2.8组件Private Sub Form_Load()Dim con As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim constr As StringDim sqlstr As Stringconstr = "driver=;server=100.1.106.10;uid=sa;pwd=admin228314;database=te"con.ConnectionString = constrcon.Opensqlstr = "select * from menu"rs.Open sqlstr, con, adOpenStatic, adLockOptimistic'rs.AddNewSet DataGrid1.DataSource = rsMe.DataGrid1.RefreshEnd Sub
随时随地看视频慕课网APP

相关分类

SQL Server
我要回答