Rs.Open strSql, Db, adOpenKeyset, adLockReadOnly在下面的程序中出现错误? 30
PrivateSubcmd_Search_Click()strSql="select*fromWENDUwhere1=1"SetRs=NewADODB.Recordset...
Private Sub cmd_Search_Click()
strSql = "select * from WENDU where 1=1"
Set Rs = New ADODB.Recordset
Rs.CursorLocation = adUseClient
Rs.Open strSql, Db, adOpenKeyset, adLockReadOnly
If Rs.RecordCount < 1 Then
MsgBox ("数据库中没有数据!")
Exit Sub
End If
Set DGrid.DataSource = Rs
DGrid.Refresh
End Sub
'存入数据库中---------------------------------------------
Sub Data_save(sinTemp As Single)
Set Rs = New ADODB.Recordset
With Rs
.Open "select * from WENDU", Db, 1, 3
.AddNew '新增一条记录
.Fields("temp") = sinTemp
.Fields("time") = DateTime.Now()
.Update
End With
'完成后关闭对象
Rs.Close
Exit Sub
errp:
errString = "Error # " & CStr(err.Number) & " " & err.Description
errtitle = err.Source
MsgBox errString, vbCritical, errtitle
End Sub
'————————————————数据库的程序
Option Explicit ' 数据库库文件和VB中创建的工程文件必须放在放同一目录下
Public Db As ADODB.Connection '全程数据库连接
Public Rs As ADODB.Recordset '查找纪录过程中引用
Dim iConcstr As String
Sub Main()
On Error GoTo errp
iConcstr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "C:\Documents and Settings\acer\桌面\界面\WDDB.mdb" & " ;Persist Security Info=False"
' '下面的语句是连接sqlserver数据库的.
Set Db = New ADODB.Connection
Db.Open iConcstr
frmmain.Show
Exit Sub
errp:
MsgBox ("数据库访问失败,或者数据库不存在,请选择有效的数据库文件!")
End Sub 展开
strSql = "select * from WENDU where 1=1"
Set Rs = New ADODB.Recordset
Rs.CursorLocation = adUseClient
Rs.Open strSql, Db, adOpenKeyset, adLockReadOnly
If Rs.RecordCount < 1 Then
MsgBox ("数据库中没有数据!")
Exit Sub
End If
Set DGrid.DataSource = Rs
DGrid.Refresh
End Sub
'存入数据库中---------------------------------------------
Sub Data_save(sinTemp As Single)
Set Rs = New ADODB.Recordset
With Rs
.Open "select * from WENDU", Db, 1, 3
.AddNew '新增一条记录
.Fields("temp") = sinTemp
.Fields("time") = DateTime.Now()
.Update
End With
'完成后关闭对象
Rs.Close
Exit Sub
errp:
errString = "Error # " & CStr(err.Number) & " " & err.Description
errtitle = err.Source
MsgBox errString, vbCritical, errtitle
End Sub
'————————————————数据库的程序
Option Explicit ' 数据库库文件和VB中创建的工程文件必须放在放同一目录下
Public Db As ADODB.Connection '全程数据库连接
Public Rs As ADODB.Recordset '查找纪录过程中引用
Dim iConcstr As String
Sub Main()
On Error GoTo errp
iConcstr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "C:\Documents and Settings\acer\桌面\界面\WDDB.mdb" & " ;Persist Security Info=False"
' '下面的语句是连接sqlserver数据库的.
Set Db = New ADODB.Connection
Db.Open iConcstr
frmmain.Show
Exit Sub
errp:
MsgBox ("数据库访问失败,或者数据库不存在,请选择有效的数据库文件!")
End Sub 展开
2个回答
2011-03-27
展开全部
YRE
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询