VB实现数据库查询并显示
vb实现数据库查询并用DBgrid显示在rs.Close处出现对象关闭时,不允许操作,代码如下,求大神指点啊。DimcnAsNewADODB.ConnectionDimr...
vb实现数据库查询并用DBgrid显示 在rs.Close处出现对象关闭时,不允许操作,代码如下 ,求大神指点啊。
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim rst As ADODB.Recordset
Private Sub Command3_Click()
rs.Close
If Text3.Text = "" Then
cmd.CommandText = "select *form 考勤信息表"
Else
cmd.CommandText = "select *form 考勤信息表 where 姓名='" & Text3.Text & "'"
rs.CursorLocation = adUseClient
rs.LockType = adLockReadOnly
End If
rs.Open cmd
Set DBGrid1.DataSource = rs
End Sub 展开
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim rst As ADODB.Recordset
Private Sub Command3_Click()
rs.Close
If Text3.Text = "" Then
cmd.CommandText = "select *form 考勤信息表"
Else
cmd.CommandText = "select *form 考勤信息表 where 姓名='" & Text3.Text & "'"
rs.CursorLocation = adUseClient
rs.LockType = adLockReadOnly
End If
rs.Open cmd
Set DBGrid1.DataSource = rs
End Sub 展开
2个回答
展开全部
你就没打开数据库怎么就关闭了?
应该先连接数据库
Private Sub Command3_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str As String
cn.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=e:\DB\db1.mdb;Persist Security Info=False")'这里边是连接字符串,看你连接什么数据库
If Text3.Text = "" Then
str = "select * from 考勤信息表"
Else
str = "select *form 考勤信息表 where 姓名='" & Text3.Text & "'"
End If
rs.Open(str, cn, ADODB.CursorTypeEnum.adOpenKeyset,ADODB.LockTypeEnum.adLockOptimistic)Set DBGrid1.DataSource = rs
cn.close
rs=nothing
cn=nothing
End Sub
rs.Open也不对
res.Open
应该先连接数据库
Private Sub Command3_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str As String
cn.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=e:\DB\db1.mdb;Persist Security Info=False")'这里边是连接字符串,看你连接什么数据库
If Text3.Text = "" Then
str = "select * from 考勤信息表"
Else
str = "select *form 考勤信息表 where 姓名='" & Text3.Text & "'"
End If
rs.Open(str, cn, ADODB.CursorTypeEnum.adOpenKeyset,ADODB.LockTypeEnum.adLockOptimistic)Set DBGrid1.DataSource = rs
cn.close
rs=nothing
cn=nothing
End Sub
rs.Open也不对
res.Open
更多追问追答
追问
rs.open怎么改。。。缺少语句结束。。
追答
rs.Open(str, cn, ADODB.CursorTypeEnum.adOpenKeyset,ADODB.LockTypeEnum.adLockOptimistic)
Set DBGrid1.DataSource = rs
这是俩句
end sub后面的都没有,忘编辑了!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询