标题:datagrid绑定recordset对象,不能显示
只看楼主
za569578898
Rank: 1
等 级:新手上路
帖 子:4
专家分:3
注 册:2012-10-24
结帖率:100%
已结贴  问题点数:20 回复次数:3 
datagrid绑定recordset对象,不能显示

Option Explicit

Public cn As String
Public cnn As New ADODB.Connection
Public comm As New
Public rs As New ADODB.Recordset
Public sqlc As String

Private Sub Form_Load()
     cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\salary\DATA\salary.mdb;Persist Security Info=False"
     sqlc = "select * from 职员"
End Sub

Private Sub Command1_Click()
  cnn.ConnectionString = cn
  cnn.Open
  rs.Open sqlc, cnn, 3, 2
  Set DataGrid1.DataSource = rs
  rs.Close
  cnn.Close
End Sub
请高手指点:
为什么无法显示数据,谢谢
 
搜索更多相关主题的帖子: False 
2013-08-06 11:24
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:10 
不要急着close,关闭了当然无数据
Private Sub Command1_Click()
  '打开  
  cnn.ConnectionString = cn
  cnn.Open
  rs.Open sqlc, cnn, 3, 2
  Set DataGrid1.DataSource = rs
End Sub
Private Sub Command2_Click()
  '关闭
  rs.Close
  cnn.Close
  Set DataGrid1.DataSource =nothing
End Sub



[ 本帖最后由 lowxiong 于 2013-8-6 12:38 编辑 ]
2013-08-06 12:36
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
得分:10 
以下是引用za569578898在2013-8-6 11:24:37的发言:


Option Explicit

Public cn As String
Public cnn As New ADODB.Connection
Public comm As New
Public rs As New ADODB.Recordset
Public sqlc As String

Private Sub Form_Load()
     cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\salary\DATA\salary.mdb;Persist Security Info=False"
     sqlc = "select * from 职员"
End Sub

Private Sub Command1_Click()
  cnn.ConnectionString = cn
  cnn.Open
  rs.Open sqlc, cnn, 3, 2
  Set DataGrid1.DataSource = rs
  rs.Close
  cnn.Close
End Sub
请高手指点:
为什么无法显示数据,谢谢
 
红色删除掉

无知
2013-08-06 12:48
za569578898
Rank: 1
等 级:新手上路
帖 子:4
专家分:3
注 册:2012-10-24
得分:0 
谢谢,搞定了
2013-08-06 13:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-418694-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.538353 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved