绑定修改不可自动保存,点击前后记录就报错,求救,求救,我急用,谢谢大家!

febricity 2004-08-23 10:02:12
我用ADODB这个控件通过ODBC和SQL SERVER相连,然后文本控件TEXTBOX和ADODB相连,连好后增加、删除都可以用,就是我在text控件中修改数据后不能保存,点前一个记录和后一个记录都报错说是操作被取消。我都绑定好了,为什么修改总是出错。
会不会是 Adodc1.Recordset.Bookmark 没设的过呢,请问 Bookmark方法如何用?
...全文
54 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
bjbs_vb 2004-08-24
估计是你输入的字符串位数与数据库字段长度有冲突,或类型不对?你查一下
回复
ryuginka 2004-08-24
不要用绑定啊
回复
febricity 2004-08-23
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

Select Case Button.Index
Case 1 ''前进 '修改后点击此键出错,且不能保存,提示操作被取消
' On Error GoTo First_err
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF = True Then
Adodc1.Recordset.MoveFirst
End If
'First_err:
' MsgBox Err.Description, vbOKOnly + vbExclamation, "警告"

Case 2 ''后退 '修改后点击此键出错,且不能保存,提示操作被取消
' On Error GoTo second_err
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MoveLast
End If
'second_err:
'MsgBox Err.Description, vbOKOnly + vbExclamation, "警告"

Case 4 ''增加
On Error GoTo add_error
Adodc1.Recordset.AddNew

add_error:
If Err.Number = 3426 Then
MsgBox "已经使用过添加记录! 错误:" & Err & "," & Err.Description, 0, "提示"
Unload Me
End If
Toolbar1.Buttons(1).Visible = False
Toolbar1.Buttons(2).Visible = False
Toolbar1.Buttons(4).Visible = False
Toolbar1.Buttons(5).Visible = True
Toolbar1.Buttons(6).Visible = True
Toolbar1.Buttons(7).Visible = False
Case 5 ''确定 ‘修改后不能保存为什么??????
On Error GoTo update_error
If Text1.Text = "" Then
MsgBox "必须填写元器件名称!", 0, "提示"
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "必须填写元器件型号!", 0, "提示"
Exit Sub
End If
‘ Adodc1.Recordset.Bookmark = Varbookmark1 ’不知如何用,在哪给Varbookmark1值

’ Adodc1.Recordset.Fields(1) = Text1
‘ Adodc1.Recordset.Fields(2) = Text2
’ Adodc1.Recordset.Update

update_error:
If Err.Number = 3020 Then
MsgBox "请先添加记录! 错误:" & Err & "," & Err.Description, 0, "提示"
Unload Me
End If
Toolbar1.Buttons(1).Visible = True
Toolbar1.Buttons(2).Visible = True
Toolbar1.Buttons(4).Visible = True
Toolbar1.Buttons(5).Visible = True
Toolbar1.Buttons(6).Visible = True
Toolbar1.Buttons(7).Visible = True
Case 6 ''取消
On Error GoTo CanceErr

' Adodc1.Recordset.Edit
Adodc1.Recordset.CancelUpdate
Toolbar1.Buttons(1).Visible = True
Toolbar1.Buttons(2).Visible = True
Toolbar1.Buttons(4).Visible = True
Toolbar1.Buttons(5).Visible = True
Toolbar1.Buttons(6).Visible = True
Toolbar1.Buttons(7).Visible = True
CanceErr:
If Err.Number = 3021 Then
MsgBox "没有记录! 错误:" & Err & "," & Err.Description, 0, "提示"
End If
Case 7 ''删除
On Error GoTo del_error
a = MsgBox("真的删除吗?", vbExclamation + vbOKCancel + vbApplicationModal, "删除记录")
If a = 1 Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveLast
End If
If a = 2 Then Exit Sub
del_error:
If Err.Number = 3426 Then
MsgBox "已经全部删除! 错误:" & Err & "," & Err.Description, 0, "提示"
Unload Me
End If
End Select
End Sub
回复
sssss342072 2004-08-23
代码搞出来,
回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2004-08-23 10:02
社区公告
暂无公告