以文本方式查看主题

-  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=11633)

--  作者:yanzhen2010
--  发布时间:2011/8/5 14:13:00
--  [求助]代码不能正确返回姓名,请指教

If e.DataCol.Name = "住院号" Then
    Dim vals() As String = e.NewValue.split(":")
    If vals.length > 2 Then
        e.DataRow("住院号") =vals(2)
    Else
        e.DataRow("住院号") =vals(0)
    End If
    Dim dr As DataRow = DataTables("入院登记").Find("[住院号] = \'" & e.NewValue & "\'")
    If dr IsNot Nothing Then
        e.DataRow("患者姓名") = dr("患者姓名")
    Else
        MsgBox("项目不存在,请重新输入!",64,"提示")
        e.DataRow("患者姓名") = Nothing
    End If
End If

 

执行后把姓名自动清空了

我的录入步骤:1、从列表项目分离出住院号,2、根据住院号找出匹配的姓名。如果没有匹配的姓名,则如下:
  MsgBox("项目不存在,请重新输入!",64,"提示")
        e.DataRow("患者姓名") = Nothing
[此贴子已经被作者于2011-8-5 14:14:06编辑过]

--  作者:狐狸爸爸
--  发布时间:2011/8/5 14:27:00
--  

Dim dr As DataRow = DataTables("入院登记").Find("[住院号] = \'" & e.NewValue & "\'")

 

改为:

 

Dim dr As DataRow = DataTables("入院登记").Find("[住院号] = \'" & e.DataRow("住院号") & "\'")


--  作者:yanzhen2010
--  发布时间:2011/8/5 15:10:00
--  
以下是引用狐狸爸爸在2011-8-5 14:27:00的发言:

Dim dr As DataRow = DataTables("入院登记"). 

改为:

 

Dim dr As DataRow = DataTables("入院登记").

我也试过,将Find("[住院号] = \'" & e.NewValue & "\'")改为Find("[住院号] = \'" & e.DataRow("住院号") & "\'")后可以返回姓名,但将住院号清空后又提示错误,姓名不能自动清空。

我的意思:

如果住院号匹配,找出匹配的姓名,

如果住院号不匹配,进行提示,

如果住院号为空,姓名为空。

[此贴子已经被作者于2011-8-5 15:12:55编辑过]

--  作者:狐狸爸爸
--  发布时间:2011/8/5 15:18:00
--  

If e.DataCol.Name = "住院号" Then
    Dim vals() As String = e.NewValue.split(":")
    If vals.length > 2 Then
        e.DataRow("住院号") =vals(2)
    Else
        e.DataRow("住院号") =vals(0)
    End If
    If e.DataRow.Isnull("住院号") Then
        e.DataRow("患者姓名") = Nothing
    Else
        Dim dr As DataRow = DataTables("入院登记").Find("[住院号] = \'" & e.DataRow("住院号") & "\'")
        If dr IsNot Nothing Then
            e.DataRow("患者姓名") = dr("患者姓名")
        Else
            MsgBox("项目不存在,请重新输入!",64,"提示")
            e.DataRow("患者姓名") = Nothing
        End If
    End If
End If

 


--  作者:mr725
--  发布时间:2011/8/5 15:25:00
--  

最前面加上一个判断:

If e.NewValue = Nothing Then

Else

    Dim vals() As String = e.NewValue.split(":")
    If vals.length > 2 Then
        e.DataRow("住院号") =vals(2)
    Else
        e.DataRow("住院号") =vals(0)
    End If

..................


--  作者:yanzhen2010
--  发布时间:2011/8/5 16:06:00
--  
以下是引用狐狸爸爸在2011-8-5 15:18:00的发言:

If e.DataCol.Name = "住院号" Then
    Dim vals() As String = e.NewValue.split(":")
    If vals.length > 2 Then
        e.DataRow("住院号") =vals(2)
    Else
        e.DataRow("住院号") =vals(0)
    End If
    If e.DataRow.Isnull("住院号") Then
        e.DataRow("患者姓名") = Nothing
    Else
        Dim dr As DataRow = DataTables("入院登记").Find("[住院号] = \'" & e.DataRow("住院号") & "\'")
        If dr IsNot Nothing Then
            e.DataRow("患者姓名") = dr("患者姓名")
        Else
            MsgBox("项目不存在,请重新输入!",64,"提示")
            e.DataRow("患者姓名") = Nothing
        End If
    End If
End If

 

不管 If e.DataRow.Isnull("住院号") Then
        e.DataRow("患者姓名") = Nothing
加在什么地方,都提示错误

是不是语言逻辑错误

清空住院号时好像和这一段有冲突 

Dim vals() As String = e.NewValue.split(":")
    If vals.length > 2 Then
        e.DataRow("住院号") =vals(2)
    Else
        e.DataRow("住院号") =vals(0)
    End If
感觉问题出在此处

[此贴子已经被作者于2011-8-5 16:15:36编辑过]

--  作者:mr725
--  发布时间:2011/8/5 16:10:00
--  

这样呢:

 

If e.DataCol.Name = "住院号" Then

 

If e.NewValue = Nothing Then

Else

    Dim vals() As String = e.NewValue.split(":")
    If vals.length > 2 Then
        e.DataRow("住院号") =vals(2)
    Else
        e.DataRow("住院号") =vals(0)
    End If
    Dim dr As DataRow = DataTables("入院登记").Find("[住院号] = \'" & e.NewValue & "\'")
    If dr IsNot Nothing Then
        e.DataRow("患者姓名") = dr("患者姓名")
    Else
        MsgBox("项目不存在,请重新输入!",64,"提示")
        e.DataRow("患者姓名") = Nothing
    End If
End If


End If

 

 

或者把:

If e.NewValue = Nothing Then

Else

换成:

   If e.DataRow.Isnull("住院号") Then

    Else

[此贴子已经被作者于2011-8-5 16:12:43编辑过]

--  作者:yanzhen2010
--  发布时间:2011/8/5 17:40:00
--  
以下是引用mr725在2011-8-5 16:10:00的发言:

这样呢:

 

If e.DataCol.Name = "住院号" Then

 

If e.NewValue = Nothing Then

Else

    Dim vals() As String = e.NewValue.split(":")
    If vals.length > 2 Then
        e.DataRow("住院号") =vals(2)
    Else
        e.DataRow("住院号") =vals(0)
    End If
    Dim dr As DataRow = DataTables("入院登记").Find("[住院号] = \'" & e.NewValue & "\'")
    If dr IsNot Nothing Then
        e.DataRow("患者姓名") = dr("患者姓名")
    Else
        MsgBox("项目不存在,请重新输入!",64,"提示")
        e.DataRow("患者姓名") = Nothing
    End If
End If


End If

 

 

或者把:

If e.NewValue = Nothing Then

Else

换成:

   If e.DataRow.Isnull("住院号") Then

    Else

[此贴子已经被作者于2011-8-5 16:12:43编辑过]

谢谢朋友,问题没有解决,清空住院号,错误依旧


--  作者:mr725
--  发布时间:2011/8/5 17:53:00
--  
你发个例子上来吧,这样来回都没有效果,说明你的东东别人没有理解或····  总之原因很多啦···
--  作者:blackzhu
--  发布时间:2011/8/5 17:55:00
--  
If e.NewValue is Nothing Then