以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  System.Data.OleDb.OleDbException (0x80040E21): 对于造型说明无效的字符值 怎么解决呢?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=186074)

--  作者:cnsjroom
--  发布时间:2023/4/5 6:34:00
--  System.Data.OleDb.OleDbException (0x80040E21): 对于造型说明无效的字符值 怎么解决呢?
Dim cmd As New SQLCommand
cmd.Conne ctionN ame = "主数据源"
cmd.CommandText = "sel ect * From 任务发布"
Dim dt As DataTable = cmd.ExecuteReader
cmd.CommandText = "se lect * from 任务台账"
Dim dt1 As DataTable = cmd.ExecuteReader(true)

Dim str As String =  e.Values("责任单位")
Dim drs As List(of DataRow) =dt .SQLSe lect("责任单位=\'"  & str  & "\' and guid=\'" & e.Values("guid") & "\'")   \'可以找到对应样本数据
For Each s As String In str.split(",")    \'对传入的值进行拆分
    For Each dr As DataRow In drs
        If dr IsNot Nothing Then
            Dim dr1 As DataRow = dt1.SQLFind("责任单位=\'"  & s & "\' and 主表guid=\'" & e.Values("guid") & "\'")
            If dr1 IsNot Nothing Then \'如果找到的话
                For Each dc As DataCol In dt.DataCols
                    dr1("责任单位")=s
                    dr1(dc.Name) = dr(dc.Name)
                    dr1("发布编号") = dr("编号")
                    dr1("发布序号") = dr("发布编号")
                    dr1("新增类型") = dr("新增类型")
                    dr1("审核状态")="待审核"
                    dr1("接收状态")="待接收"
                    dr1("办理状态")="待办理"
                Next
            Else
                dr1 = dt1.AddNew
                msg(1)
                For Each dc As DataCol In dt.DataCols
                    dr1("guid")=guid.newguid.tostring()
                    dr1("主表guid")=dr("guid")
                    dr1("所属部门guid")=dr("所属部门guid")
                    dr1("责任单位")=s
                    dr1("发布guid")=dr("guid")
                    dr1(dc.Name) = dr(dc.Name)
                    dr1("发布编号") = dr("编号")
                    dr1("发布序号") = dr("发布编号")
                    dr1("新增类型") = dr("新增类型")
                    dr1("审核状态")="待审核"
                    dr1("接收状态")="待接收"
                    dr1("办理状态")="待办理"
                Next
                Dim cmd1 As SQLCommand = rq.cmd
                msg(2)
                cmd1.CommandText ="s el ect * from 任务台账 where 责任单位=\'"  & s & "\' and 主表guid=\'" & e.Values("guid") & "\'"
                msg(cmd1.CommandText)
                Dim dt11 As DataTable = cmd1.ExecuteReader()
                Dim dd As Datetime = Date.now
                If dt11.DataRows.Count>0 Then
                    Dim dr11 As DataRow =dt11.DataRows(0)
                    dd = dr11("创建日期")
                    msg(31)
                End If
                msg(32)
                Dim id,id1 As String
                Dim dw As String
                Dim tk As String
                Dim cmd2 As SQLCommand = rq.cmd
                Dim AA,AA1 As String
                Dim WW,WW1 As String
                msg(3)
                cmd2.CommandText = "se le ct 部门识别码,单位简称,部门简称 from sys_Department where guid=\'" & e.Values("所属部门guid") & "\' "
                Dim Values1 = cmd2.ExecuteValues
                If Values1.Count > 0 Then
                    AA = Values1("部门识别码").tostring
                    AA1 = Values1("单位简称").tostring
                    WW1 = Values1("部门简称").tostring
                End If
                msg(4)
                cmd2.CommandText ="s el ect * from SYS_编号 where 名称=\'台账编号\'"
                Dim dt2 As DataTable = cmd2.ExecuteReader()
                If dt2.DataRows.Count>0 Then
                    Dim dr2 As DataRow =dt2.DataRows(0)
                    id =SetNumber004(dr2("guid"),0,"",dd,AA,WW)
                End If
                msg(5)
                cmd2.CommandText ="se le ct * from SYS_编号 where 名称=\'单位台账编号\'"
                Dim dt21 As DataTable = cmd2.ExecuteReader()
                If dt21.DataRows.Count>0 Then
                    Dim dr21 As DataRow =dt21.DataRows(0)
                    id1 =SetNumber005(dr21("guid"),0,"",dd,AA1,WW1)
                End If
                
                msg(6)
                dr1("编号") =  id1
                dr1("台账编号") =  id
            End If
            msg(7)
            dr1.save
        End If
    Next
Next
msg(8)
dt1.save
msg(90)
cmd.CommandText = "Sele ct 编号,发布编号 from {任务发布} Where guid=\'" & e.Values("guid") & "\'"
msg(cmd.CommandText)
Dim Values = cmd.ExecuteValues
If Values.Count > 0 Then
    Dim Products As List(Of String)
    Products = dt.SQ LGetValues("guid","guid=\'" & e.Values("guid") & "\'")
    For Each Product As String In Products
        cmd.CommandText = "UPD ATE {任务台账} SET 发布编号 = \'" & Values("编号") & "\',发布序号 = \'" & Values("发布编号") & "\'  WHERE 主表guid=\'" & Product & "\'"
        msg(cmd.CommandText)
        cmd.ExecuteNonQuery()
    Next
    msg(9)
End If



输出:【上述红色部分出错误】
90
2023-04-05 06:30:41
错误的事件名称
System.Data.OleDb.OleDbException (0x80040E21): 对于造型说明无效的字符值
   在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   在 System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
   在 System.Data.Common.DbDataAdapter.UpdateRowExecute(RowUpdatedEventArgs rowUpdatedEvent, IDbCommand dataCommand, StatementType cmdIndex)
   在 System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
2023-04-05 06:30:40
8
2023-04-05 06:30:40
错误的事件名称
System.Data.OleDb.OleDbException (0x80040E21): 对于造型说明无效的字符值
   在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   在 System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
   在 System.Data.Common.DbDataAdapter.UpdateRowExecute(RowUpdatedEventArgs rowUpdatedEvent, IDbCommand dataCommand, StatementType cmdIndex)
   在 System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
2023-04-05 06:30:40
7
2023-04-05 06:30:40
[此贴子已经被作者于2023/4/5 6:34:27编辑过]

--  作者:有点蓝
--  发布时间:2023/4/6 8:36:00
--  
这个错误和日期值有关,应该是哪里的日期值有问题