以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]从字符串到类型“Long”的转换无效??  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=116071)

--  作者:jjjeyes
--  发布时间:2018/3/19 15:18:00
--  [求助]从字符串到类型“Long”的转换无效??
If e.DataCol.Name = "学号" Then 
    If e.NewValue Is Nothing Then 
        e.DataRow("姓名") = Nothing 
    Else
        Dim dr As DataRow
        Dim d1 As DataRow
        dr = DataTables("成绩详细").Find("[学号] = \'" & e.NewValue & "\'")
        d1 = DataTables("成绩详细").Find("[学号] = \'" & e.NewValue & "\'" And "[年级编号] = \'41\'")
        If dr IsNot Nothing Then 
            e.DataRow("姓名") = dr("姓名")
            e.DataRow("班级") = dr("班级")
            e.DataRow("学院") = dr("学院")
            e.DataRow("大一成绩") = d1("总分")
        End If
    End If
End If

以上为代码,为什么在学号列输入学号后总是显示:

调用的目标发生了异常。
从字符串“[学号] = \'20144673002\'”到类型“Long”的转换无效。
输入字符串的格式不正确。

--  作者:有点甜
--  发布时间:2018/3/19 15:20:00
--  

d1 = DataTables("成绩详细").Find("[学号] = \'" & e.NewValue & "\'" And "[年级编号] = \'41\'")

 

改成

 

d1 = DataTables("成绩详细").Find("[学号] = \'" & e.NewValue & "\' And [年级编号] = \'41\'")


--  作者:jjjeyes
--  发布时间:2018/3/19 15:25:00
--  
我的天啊,就因为多了个引号?
--  作者:有点甜
--  发布时间:2018/3/19 15:26:00
--  

 表达式合成,参考

 

http://www.foxtable.com/webhelp/scr/1647.htm