找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 378|回复: 9

[求助]如何实现出错处理(急)

[复制链接]
发表于 2009-11-18 00:27:05 | 显示全部楼层 |阅读模式 IP:江苏扬州
这是用vb编的一段关于查询的代码,哪位高手能帮忙加入出错处理的代码吗,就是判断如果数据库中没有这个记录,则出现提示信息。谢谢哪位高手帮忙啊,急!!!!!!!!!!!!!!!!!!!!!!!!



另外哪位高手知道怎么实现只修改数据库的一项,然后把修改的值返回数据库的代码吗,谢谢。





Private Sub cmdInquire_Click()
Dim txtSQL As String
Dim MsgText As String
Dim dd(4) As Boolean
Dim mrc As ADODB.Recordset


txtSQL = "select * from result_Info where "
If Check1(0).Value Then
If Trim(txtSID.Text) = "" Then
sMeg = "学号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtSID.SetFocus
Exit Sub
Else
If Not IsNumeric(Trim(txtSID.Text)) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Exit Sub
txtSID.SetFocus
End If
dd(0) = True
txtSQL = txtSQL & "student_ID = '" & Trim(txtSID.Text) & "'"
End If
End If

If Check1(1).Value Then
If Trim(txtName.Text) = "" Then
sMeg = "姓名不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtName.SetFocus
Exit Sub
Else
dd(1) = True
If dd(0) Then
txtSQL = txtSQL & "and student_Name = '" & txtName.Text & "'"
Else
txtSQL = txtSQL & "student_Name = '" & txtName.Text & "'"
End If
End If
End If

If Check1(2).Value Then
If Trim(txtCourse.Text) = "" Then
sMeg = "课程不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtCourse.SetFocus
Exit Sub
Else
dd(2) = True
If dd(0) Or dd(1) Then
txtSQL = txtSQL & "and course_Name = '" & txtCourse.Text & "'"
Else
txtSQL = txtSQL & "course_Name = '" & txtCourse.Text & "'"
End If
End If
End If

If Not (dd(0) Or dd(1) Or dd(2) Or dd(3)) Then
MsgBox "请设置查询方式!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If

txtSQL = txtSQL & " order by student_ID "
Set mrc = ExecuteSQL(txtSQL, MsgText)

With myflexgrid
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 0) = "考试编号"
.TextMatrix(1, 1) = "学号"
.TextMatrix(1, 2) = "姓名"
.TextMatrix(1, 3) = "班号"
.TextMatrix(1, 4) = "课程名称"
.TextMatrix(1, 5) = "分数"


Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 3) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4)
.TextMatrix(.Rows - 1, 5) = mrc.Fields(5)
mrc.MoveNext
Loop

End With

mrc.Close
End Sub
发表于 2009-11-18 00:27:06 | 显示全部楼层 IP:江苏扬州
在线等高手帮忙啊
回复

使用道具 举报

发表于 2009-11-18 00:27:06 | 显示全部楼层 IP:江苏扬州
用SELECT语句查询后加上这个判断
If mrc.BOF = True And mrc.EOF = True Then
MsgBox ("没有数据!")
End If
回复

使用道具 举报

发表于 2009-11-18 00:27:07 | 显示全部楼层 IP:江苏扬州
是在我这个程序基础上加这句吗?另外一个问题呢?
回复

使用道具 举报

发表于 2009-11-18 00:27:08 | 显示全部楼层 IP:江苏扬州
直接用SQL语句就可以实现只修改一项啊
updat 列名 FROM 表 WHERE 条件
回复

使用道具 举报

发表于 2009-11-18 00:27:09 | 显示全部楼层 IP:江苏扬州
能说具体点吗,不是很明白啊,写一段代码吧
回复

使用道具 举报

发表于 2009-11-18 00:27:10 | 显示全部楼层 IP:江苏扬州
那位高手给出修改某一项的代码啊
回复

使用道具 举报

发表于 2009-11-18 00:27:11 | 显示全部楼层 IP:江苏扬州
谁知道啊
回复

使用道具 举报

发表于 2009-11-18 00:27:13 | 显示全部楼层 IP:江苏扬州
如果要说错误处理应用
on error goto procerror

'''''''''''''''程序段

procexit:
exit sub

procerror
''''''''错误处理段
resume procexit ''''''根据需要可改为resume next
回复

使用道具 举报

发表于 2009-11-18 00:27:14 | 显示全部楼层 IP:江苏扬州
判断是否有记录可用if mrc.AbsolutePosition = adPosUnknown then来判断。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-29 13:20 , Processed in 0.292039 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表