以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  sqlfind不能save?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=135595)

--  作者:lur320
--  发布时间:2019/5/29 20:39:00
--  sqlfind不能save?
Dim cb1 As WinForm.ComboBox = e.Form.Controls("ComboBox1")
If cb1.value <>"" Then
    Dim Result As DialogResult
    Result = MessageBox.Show("是否从所选手册编号拷贝一份草稿?  并且覆盖当前的草稿?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    If Result = DialogResult.Yes Then
        Dim dr As DataRow
        dr=DataTables("customBOMtitle").SQLFind("手册编号=\'" & cb1.value & "\'")
        
        Dim dr2 As DataRow
        dr2= DataTables("customBOMtitle").SQLFind("手册编号 = \'Draft\' or 手册编号 is null")
        If dr2 Is Nothing Then
            dr2= DataTables("customBOMtitle").addnew
            
        End If
        
        For Each dc As DataCol In DataTables("customBOMtitle").DataCols
            If dc.Name <> "attachloc" Then
                
                dr2(dc.Name) = dr(dc.Name)
            End If
            If dc.Name = "手册编号" Then
                
                dr2(dc.Name) = "Draft"
            End If
        Next
                dr2.save()
            End If
End If

当dr2不为空,不是新增的行的时候。运行到dr2。save会报错。为何?

--  作者:lur320
--  发布时间:2019/5/29 20:42:00
--  
Invalid character value for cast specification.
--  作者:有点甜
--  发布时间:2019/5/29 21:00:00
--  

 

当使用SQLfind的时候,录入时间为空的时候,请赋值为nothing,不要直接使用 dr2(dc.Name) = dr(dc.Name) 赋值。
 
 

--  作者:lur320
--  发布时间:2019/5/29 21:07:00
--  
果然。修改一下就ok了
 For Each dc As DataCol In DataTables("customBOMtitle").DataCols
            
            
            Select Case dc.Name
                Case "有效日期","申报日期","录入日期"
                    If dr.IsNull(dc.name)     Then
                        
                        dr2(dc.Name) = Nothing
                    Else
                        dr2(dc.Name) = dr(dc.name)
                    End If
                    
                Case "attachloc"
                    Continue For
                Case "