| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 404 人关注过本帖
标题:这是怎么回事,请大家指点
只看楼主 加入收藏
alalei_2006
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-5-8
收藏
 问题点数:0 回复次数:1 
这是怎么回事,请大家指点

“修改窗体”刚打开时能显示完整的记录,但是一运行“查询”以后,再回到“修改”窗体时,修改里面的记录竟然只有上个“查询”窗体查询的结果了。如下图:


“修改窗体”的代码

Sub RefreshGrid()

DataGrid1.DataMember = ""

DataGrid1.Refresh

Dataenv.rsdepartment.Requery

DataGrid1.DataMember = "department"

DataGrid1.Refresh

End Sub

Private Sub Cmdcancel_Click()

Dataenv.rsdepartment.CancelUpdate

DataGrid1.Refresh

DataGrid1.AllowAddNew = False

DataGrid1.AllowUpdate = False

cmdmodify.Enabled = True

cmddel.Enabled = True

cmdcancel.Enabled = False

cmdupdate.Enabled = False

Unload Me

End Sub

Private Sub cmddel_Click()

On Error GoTo errHandler

If MsgBox("要删除记录?", vbYesNo + vbQuestion + vbDefaultButton2, "确认") = vbYes Then

''通过在DataEnv.Con中执行SQL命令,来删除记录

Dataenv.con.Execute "delete from department where id =" & DataGrid1.Columns(0).CellText(DataGrid1.Bookmark) & " "

Dataenv.rsdepartment.MoveNext

If Dataenv.rsdepartment.EOF Then Dataenv.rsdepartment.MoveLast

''刷新用户导航的网格控件

Call RefreshGrid

End If

Exit Sub

errHandler:

MsgBox Err.Description, vbCritical, "错误"

End Sub

Private Sub Cmdmodify_Click()

Dim answer As String

On Error GoTo cmdmodify

cmddel.Enabled = False

cmdmodify.Enabled = False

cmdupdate.Enabled = True

cmdcancel.Enabled = True

DataGrid1.AllowUpdate = True

cmdmodify:

If Err.Number <> 0 Then

MsgBox Err.Description

End If

End Sub

Private Sub Cmdupdate_Click()

If Not IsNull(DataGrid1.Bookmark) Then

Dataenv.rsdepartment.Update

End If

cmdmodify.Enabled = True

cmddel.Enabled = True

cmdcancel.Enabled = True

cmdupdate.Enabled = False

DataGrid1.AllowUpdate = True

MsgBox "修改成功!", vbOKOnly + vbExclamation, ""

End Sub

Private Sub Form_Load()

On Error GoTo loaderror

cmdupdate.Enabled = False

'设定datagrid控件属性

DataGrid1.AllowAddNew = False '不可增加

DataGrid1.AllowDelete = False '不可删除

DataGrid1.AllowUpdate = False

Exit Sub

loaderror:

MsgBox Err.Description

End Sub

查询窗体的代码

Sub RefreshGrid()

DataGrid1.DataMember = ""

DataGrid1.Refresh

If Dataenv.rsdepartment.State <> adStateClosed Then Dataenv.rsdepartment.Close

Dataenv.rsdepartment.Open

DataGrid1.DataMember = "department"

DataGrid1.Refresh

End Sub

Private Sub Command1_Click()

Dim rsdep As New Recordset

Dim sql As String

sql = "select * from department where "

If Check1.Value = 1 Or Check2.Value = 1 Then

If Check1.Value = 1 And Check2.Value = 1 Then

sql = sql & "id= " & Trim(Text1.Text) & " " & "and" & " name = '" & Trim(cbodep.Text) & "'"

Else

If Check1.Value = 1 Then

sql = sql & "id=" & Text1.Text & " "

End If

If Check2.Value = 1 Then

sql = sql & "name='" & cbodep.Text & "'"

End If

End If

End If

With Dataenv.rsdepartment

If .State = adStateOpen Then .Close

.Open sql, Dataenv.con

End With

Call RefreshGrid

End Sub

Private Sub Command2_Click()

Unload Me

End Sub

Private Sub Form_Load()

Text1.Text = Empty

cbodep.Text = Empty

With Dataenv.rsdepartment

cbodep.Clear

If .State <> adStateOpen Then .Open

.MoveFirst

While Not .EOF

cbodep.AddItem Dataenv.rsdepartment("Name")
.MoveNext

Wend

End With

End Sub

[此贴子已经被作者于2006-5-20 22:00:19编辑过]

搜索更多相关主题的帖子: 查询 
2006-05-20 21:59
dream1234
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-5-22
收藏
得分:0 

呵呵!你好好想一想呀!你一开始的时候你的数据是数据库中的所有数据,但是你运行了查询之后,你已经修改了原来的数据了呀!只要你把它在恢复回去就可以了呀!在你要恢复的地放加上下面的这个语句应该就可了呀!你试试吧!
Open "select * from department", Dataenv.con

2006-05-22 22:03
快速回复:这是怎么回事,请大家指点
数据加载中...
 
   



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

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