| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1349 人关注过本帖, 1 人收藏
标题:请教,datagrid不加载数据库记录问题
取消只看楼主 加入收藏
enirilt
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-11-29
结帖率:0
收藏(1)
 问题点数:0 回复次数:7 
请教,datagrid不加载数据库记录问题
公用模块代码:
Option Explicit
Public DB As ADODB.Connection
Public RS As ADODB.Recordset
Public RS1, RS2 As ADODB.Recordset
Public sqlStr As String
Public sqlStrX As String
Public strX(5) As String
Public Sub DataBase()
    Set DB = New ADODB.Connection
    DB.Open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\EMS.mdb;Persist Security Info=False"
    Set RS = New ADODB.Recordset
    RS.Open "select * from teachers", DB, adOpenKeyset, adLockPessimistic
    Set RS1 = New ADODB.Recordset
    Set RS2 = New ADODB.Recordset
    RS1.Open "select distinct 姓名 from teachers", DB, adOpenKeyset, adLockPessimistic
    RS2.Open "select distinct 编号 from teachers", DB, adOpenKeyset, adLockPessimistic
   
End Sub
Public Sub Rsize()
frmTeachers.DGteachers.RowHeight = 250
frmTeachers.DGteachers.Columns(0).Width = 1500
frmTeachers.DGteachers.Columns(1).Width = 800
frmTeachers.DGteachers.Columns(2).Width = 600
frmTeachers.DGteachers.Columns(3).Width = 800
frmTeachers.DGteachers.Columns(4).Width = 1200
frmTeachers.DGteachers.Columns(5).Width = 3000
frmTeachers.DGteachers.Columns(6).Width = 600
End Sub
frm窗体代码:
Private Sub Combo1_Change(Index As Integer)
    strX(Index) = Combo1(Index).Text
    If Index < 2 Then
        Call RefreshX2
    Else
        Call RefreshX1
    End If
End Sub

Private Sub Combo1_Click(Index As Integer)
strX(Index) = Combo1(Index).Text
    If Index < 2 Then
        Call RefreshX2
    Else
        Call RefreshX1
    End If
End Sub

Private Sub Form_Load()
    For i = 0 To 4
        Combo1(i).AddItem "所有"
    Next
    Call Init

End Sub
Sub Init()
Call DataBase
Set DGteachers.DataSource = RS
Call Rsize
Do While Not RS1.EOF
    Combo1(0).AddItem RS1("姓名")
    RS1.MoveNext
Loop
    Do While Not RS2.EOF
    Combo1(1).AddItem RS2("编号")
    RS2.MoveNext
Loop
    With Combo1(2)
    .AddItem "男"
    .AddItem "女"
    End With
    With Combo1(3)
    .AddItem "教授"
    .AddItem "副教授"
    .AddItem "讲师"
    .AddItem "助教"
    End With
    With Combo1(4)
    .AddItem "物理系"
    .AddItem "化学系"
    .AddItem "新闻系"
    .AddItem "翻译系"
    .AddItem "行管系"
    End With
End Sub
Sub RefreshX()
    RS.Close
    RS.Open "select * from teachers", DB, adOpenKeyset, adLockPessimistic
    Set DGteachers.DataSource = RS
    Call Rsize
    For i = 0 To 4
        strX(i) = "所有"
    Next
End Sub
Sub RefreshX1()
RS.Close
sqlStrX = "select * from teachers where 姓名 like '%'"
    If strX(2) <> "所有" And strX(2) <> "" Then
        sqlStrX = sqlStrX & "and 性别='" & strX(2) & "'"
    End If
    If strX(3) <> "所有" And strX(3) <> "" Then
        sqlStrX = sqlStrX & "and 职称='" & strX(3) & "'"
    End If
    If strX(4) <> "所有" And strX(4) <> "" Then
        sqlStrX = sqlStrX & "and 所在系='" & strX(4) & "'"
    End If
RS.Open sqlStrX, DB, adOpenKeyset, adLockPessimistic
Set DGteachers.DataSource = RS
Call Rsize
End Sub
Sub RefreshX2()
RS.Close
    If strX(0) <> "所有" And strX(1) <> "" Then
        sqlStrX = "select * from teachers where 姓名 like '%" & strX(0) & "%'"
    Else
    sqlStrX = "select * from teachers where 姓名 like '%'"
    End If
    If strX(1) <> "所有" And strX(1) <> "" Then
        sqlStrX = sqlStrX & "and 编号 like '%" & strX(1) & "%'"
    End If
RS.Open sqlStrX, DB, adOpenKeyset, adLockPessimistic
Set DGteachers.DataSource = RS
Call Rsize
End Sub
问题是运行不报错,可DATAGrid控件不显示数据记录
搜索更多相关主题的帖子: 数据库 
2011-02-19 16:51
enirilt
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-11-29
收藏
得分:0 
应用:microsoft activex data objects 2.8 library
部件:microsoft datagrid control6.0 (sp5)(oledb)
都上了,还需要上什么?
2011-02-19 19:49
enirilt
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-11-29
收藏
得分:0 
演练项目.rar (20.23 KB)
2011-02-19 20:57
enirilt
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-11-29
收藏
得分:0 
登录:ent 密码:123 管理员
2011-02-19 21:27
enirilt
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-11-29
收藏
得分:0 
工程文件看了吗?问题在哪?我是跟着书上的例子学呢,所以想知道存在的问题
2011-02-20 08:53
enirilt
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-11-29
收藏
得分:0 
是的,帮我调试一下吗?辛苦了,谢谢!
2011-02-20 15:46
enirilt
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-11-29
收藏
得分:0 
非常感谢!帮我解决了问提,也提了宝贵的建议,谢谢!顺便问下怎么结贴?
2011-02-20 19:47
enirilt
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-11-29
收藏
得分:0 
记住了,下次一定招办
2011-02-21 07:59
快速回复:请教,datagrid不加载数据库记录问题
数据加载中...
 
   



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

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