以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  删除记录问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=78947)

--  作者:digger_deng
--  发布时间:2015/12/21 12:46:00
--  删除记录问题
我写了一段代码,目的是在删除父表(课程表)时,如果对应的子表(学习记录)有记录就提示不能删除!总是报错“未找到列 [xh]。”
Dim xh As String
Dim tbl As Table = Tables("课程表")
If tbl.Current IsNot Nothing Then
   xh= tbl.Current("序号")
End If
messagebox.show(xh)
Dim dr As DataRow
dr = DataTables("学习记录").Find("序号=xh")
If dr IsNot Nothing Then \'如果找到的话
  MessageBox.Show("此班级还有学生,不能删除!")

Else
 MessageBox.Show("此班级没有学生,可以删除!")

End If

--  作者:e-png
--  发布时间:2015/12/21 13:00:00
--  
你的列名是 序号 还是 xh?
--  作者:digger_deng
--  发布时间:2015/12/21 13:18:00
--  
“序号”是学习记录表的列名,xh是定义的字符变量。目的是只有在子表“学习记录”删空后,父表“课程表”才允许删除。
[此贴子已经被作者于2015/12/21 13:23:13编辑过]

--  作者:狐表开发
--  发布时间:2015/12/21 14:04:00
--  
Dim xh As String
Dim tbl As Table = Tables("课程表")
If tbl.Current IsNot Nothing Then
   xh= tbl.Current("序号")
End If
messagebox.show(xh)
Dim dr As DataRow
dr = DataTables("学习记录").Find("序号 = \'" & xh & "\'")
If dr IsNot Nothing Then \'如果找到的话
  MessageBox.Show("此班级还有学生,不能删除!")

Else
 MessageBox.Show("此班级没有学生,可以删除!")

End If

--  作者:digger_deng
--  发布时间:2015/12/21 14:38:00
--  
非常感谢。