以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]代码不运行及出现对话框的原因  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=89507)

--  作者:33chyh
--  发布时间:2016/8/23 15:20:00
--  [求助]代码不运行及出现对话框的原因

老师好!我在“卷1答”表中增加一行,随之在“卷1频”、“卷1问”、“成绩”三个表中都要增加一行。在“卷1答”表中填写试卷号和姓名时,其他三个表也要出现对应的试卷号和姓名。在运行下列代码时,后三个表都没有变化。同时出现一个对话框,见下图。请您帮助我看看哪些代码写的有问题?

运行时图片:

 
图片点击可在新窗口打开查看此主题相关图片如下:捕获1.jpg
图片点击可在新窗口打开查看

代码如下:

Dim cjdr As DataRow = DataTables("成绩").Find("学号 = \'" & e.DataRow("学号") & "\'" And "姓名 = \'" & e.DataRow("姓名") & "\'")
Dim ndr1 As DataRow = DataTables("卷1问").Find("学号 = \'" & e.DataRow("学号") & "\'" And "姓名 = \'" & e.DataRow("姓名") & "\'")
Dim ndr2 As DataRow = DataTables("卷1频").Find("学号 = \'" & e.DataRow("学号") & "\'" And "姓名 = \'" & e.DataRow("姓名") & "\'")
If cjdr Is Nothing OrElse ndr1 Is Nothing OrElse ndr2 Is Nothing Then  \'这是一个将相关表格进行同时增加行的条件代码
    cjdr = DataTables("成绩").AddNew
    cjdr("学号") = e.DataRow("学号")
    cjdr("姓名") = e.DataRow("姓名")
    ndr1 = DataTables("卷1问").AddNew
    ndr1("学号") = e.DataRow("学号")
    ndr1("姓名") = e.DataRow("姓名")
    ndr2 = DataTables("卷1频").AddNew
    ndr2("学号") = e.DataRow("学号")
    ndr2("姓名") = e.DataRow("姓名")
End If

文件如下:

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目12.foxdb


--  作者:大红袍
--  发布时间:2016/8/23 15:46:00
--  
If e.DataCol.name = "学号" OrElse e.DataCol.name = "姓名" Then
    If e.DataRow.IsNull("学号") = False AndAlso e.DataRow.IsNull("姓名") = False Then
        Dim cjdr As DataRow = DataTables("成绩").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
        Dim ndr1 As DataRow = DataTables("卷1问").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
        Dim ndr2 As DataRow = DataTables("卷1频").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
        If cjdr Is Nothing Then
            cjdr = DataTables("成绩").AddNew
        End If
        cjdr("学号") = e.DataRow("学号")
        cjdr("姓名") = e.DataRow("姓名")
        If ndr1 Is Nothing Then
            ndr1 = DataTables("卷1问").AddNew
        End If
        ndr1("学号") = e.DataRow("学号")
        ndr1("姓名") = e.DataRow("姓名")
        If ndr2 Is Nothing Then
            ndr2 = DataTables("卷1频").AddNew
        End If
        ndr2("学号") = e.DataRow("学号")
        ndr2("姓名") = e.DataRow("姓名")
    End If
End If

--  作者:33chyh
--  发布时间:2016/8/23 16:01:00
--  
谢谢大红袍老师的帮助!经过测试代码能完成我的设想。再一次感谢您!!!
--  作者:33chyh
--  发布时间:2016/8/23 18:57:00
--  

大红袍老师您好!我将您提供的代码放到程序文件中与其他代码组合后运行出现如下图情况,通过查找原因应该是“If e.DataRow.IsNull("学号") = False AndAlso e.DataRow.IsNull("姓名") = False Then”这一代码出现问题,经过尝试改动,都没有成功,请您看看它和其他代码之间出现什么问题?

出现问题图片如下:

 
图片点击可在新窗口打开查看此主题相关图片如下:整合6.jpg
图片点击可在新窗口打开查看

代码如下:

If e.DataCol.name = "学号" OrElse e.DataCol.name = "姓名" Then
    If e.DataRow.IsNull("学号") = False AndAlso e.DataRow.IsNull("姓名") = False Then
    Dim ndr As DataRow = DataTables("成绩").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
        Dim ndr1 As DataRow = DataTables("卷1问").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
        Dim ndr2 As DataRow = DataTables("卷1频").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
        If ndr Is Nothing Then
            ndr = DataTables("成绩").AddNew
        End If
        ndr("学号") = e.DataRow("学号")
        ndr("姓名") = e.DataRow("姓名")
        If ndr1 Is Nothing Then
            ndr1 = DataTables("卷1问").AddNew
        End If
        ndr1("学号") = e.DataRow("学号")
        ndr1("姓名") = e.DataRow("姓名")
        If ndr2 Is Nothing Then
            ndr2 = DataTables("卷1频").AddNew
        End If
        ndr2("学号") = e.DataRow("学号")
        ndr2("姓名") = e.DataRow("姓名")
    End If
End If
Dim kgtcj,zgtcj As Integer  \'声明记录客观题和主观题成绩变量
Dim cjdr As DataRow = DataTables("成绩").Find("学号 = \'" & e.DataRow("学号") & "\'" And "姓名 = \'" & e.DataRow("姓名") & "\'")
For i As Integer = 1 To 3
    Dim fkgdr As DataRow = DataTables("客观题答案").find("客观题" & i & " = \'" & e.DataRow("客观题" & i) & "\' And 试卷号 = \'" & DataTables("卷1答").name.Chars(1) & "\'")
    If fkgdr IsNot Nothing Then
        kgtcj + = 1
    End If
Next
For i As Integer = 1 To 7
    If e.DataRow("主观题" & i ) = "t" Then
        zgtcj + = 1
    End If
Next
cjdr("卷1") = kgtcj + zgtcj \'给成绩表格相关试卷赋分代码

文件如下:

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目13.foxdb



--  作者:大红袍
--  发布时间:2016/8/23 22:09:00
--  
Dim kgtcj,zgtcj As Integer  \'声明记录客观题和主观题成绩变量
Dim cjdr As DataRow = DataTables("成绩").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
If cjdr IsNot Nothing
    For i As Integer = 1 To 3
        Dim fkgdr As DataRow = DataTables("客观题答案").find("客观题" & i & " = \'" & e.DataRow("客观题" & i) & "\' And 试卷号 = \'" & DataTables("卷1答").name.Chars(1) & "\'")
        If fkgdr IsNot Nothing Then
            kgtcj + = 1
        End If
    Next
    For i As Integer = 1 To 7
        If e.DataRow("主观题" & i ) = "t" Then
            zgtcj + = 1
        End If
    Next
    cjdr("卷1") = kgtcj + zgtcj \'给成绩表格相关试卷赋分代码
End If

--  作者:33chyh
--  发布时间:2016/8/24 7:57:00
--  

老师您好!经过与其他代码一起运行发现出现问题。“卷1答”表中插入一行并填写“13”后回车会出现一个提示“运行错误”对话框,内容见下图。

 
图片点击可在新窗口打开查看此主题相关图片如下:整合7.jpg
图片点击可在新窗口打开查看

输入姓名后,其他表中会出现下图所示,同时还会出现一个相同的提示“运行错误”对话框。请您帮我看看这是什么原因造成的?

 
图片点击可在新窗口打开查看此主题相关图片如下:整合8.jpg
图片点击可在新窗口打开查看

运行代码如下:

If e.DataCol.name = "学号" OrElse e.DataCol.name = "姓名" Then
    If e.DataRow.IsNull("学号") = False AndAlso e.DataRow.IsNull("姓名") = False Then
        Dim cjdr1 As DataRow = DataTables("成绩").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
        Dim ndr1 As DataRow = DataTables("卷1问").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
        Dim ndr2 As DataRow = DataTables("卷1频").Find("学号 = \'" & e.DataRow("学号") & "\' And 姓名 = \'" & e.DataRow("姓名") & "\'")
        If cjdr1 Is Nothing Then
            cjdr1 = DataTables("成绩").AddNew
        End If
        cjdr1("学号") = e.DataRow("学号")
        cjdr1("姓名") = e.DataRow("姓名")
        If ndr1 Is Nothing Then
            ndr1 = DataTables("卷1问").AddNew
        End If
        ndr1("学号") = e.DataRow("学号")
        ndr1("姓名") = e.DataRow("姓名")
        If ndr2 Is Nothing Then
            ndr2 = DataTables("卷1频").AddNew
        End If
        ndr2("学号") = e.DataRow("学号")
        ndr2("姓名") = e.DataRow("姓名")
    End If
End If
Dim kgtcj,zgtcj As Integer  \'声明记录客观题和主观题成绩变量
Dim cjdr As DataRow = DataTables("成绩").Find("学号 = \'" & e.DataRow("学号") & "\'" And "姓名 = \'" & e.DataRow("姓名") & "\'")
For i As Integer = 1 To 3
    Dim fkgdr As DataRow = DataTables("客观题答案").find("客观题" & i & " = \'" & e.DataRow("客观题" & i) & "\' And 试卷号 = \'" & DataTables("卷1答").name.Chars(1) & "\'")
    If fkgdr IsNot Nothing Then
        kgtcj + = 1
    End If
Next
For i As Integer = 1 To 7
    If e.DataRow("主观题" & i ) = "t" Then
        zgtcj + = 1
    End If
Next
cjdr("卷1") = kgtcj + zgtcj \'给成绩表格相关试卷赋分代码

 

文件如下:

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目13.foxdb




--  作者:Hyphen
--  发布时间:2016/8/24 8:53:00
--  
Dim cjdr As DataRow = DataTables("成绩").Find("学号 = \'" & e.DataRow("学号") & "\'" And "姓名 = \'" & e.DataRow("姓名") & "\'")

改成
Dim cjdr As DataRow = DataTables("成绩").Find("学号 = \'" & e.DataRow("学号") & "\'" And 姓名 = \'" & e.DataRow("姓名") & "\'")


--  作者:33chyh
--  发布时间:2016/8/24 10:02:00
--  

谢谢两位老师,您提供的代码已经解决我的问题了。同时也学到了不少东西。谢谢!!!