none
WCF如何更新DataTable? RRS feed

  • 问题

  • DataSet采用数据集设计器设计,并添加数据验证,类似如下代码:

     

        Private Sub DataTable_RowChanged(ByVal sender As System.Object, ByVal e As cpRowChangeEvent) Handles Me.cpRowChanged
                If {DataRowState.Added, DataRowState.Modified}.Contains(e.Row.RowState) = False Then Return

                If String.IsNullOrWhiteSpace(e.Row.bh) = True Then
                    e.Row.SetColumnError("bh", ErrEmpty)
                Else
                    e.Row.SetColumnError("bh", "")
                End If
               ......
            End Sub

    WCF接口:

    <ServiceContract()>
    Public Interface IService1

        <OperationContract()> Function UpdateCp(ByVal cp As Sjj.erpDataSet.cpDataTable) As Integer
        <OperationContract()> Function UpdateDataSet(ByVal ds As Sjj.erpDataSet) As Integer

    ......

    End Interface

    '更新单个表

        Public Function UpdateCp(ByVal cp As Sjj.erpDataSet.cpDataTable) As Integer Implements IService1.UpdateCp
            Dim ta As New Sjspq.erpDataSetTableAdapters.cpTableAdapter
            Return ta.Update(cp)
        End Function

    '更新整个数据集

        Public Function UpdateDataSet(ByVal ds As Sjj.erpDataSet) As Integer Implements IService1.UpdateDataSet
            Dim ta As New Sjspq.erpDataSetTableAdapters.TableAdapterManager
            With ta
                     .cpTableAdapter = New Sjspq.erpDataSetTableAdapters.cpTableAdapter
     ......

            End With
            Return ta.UpdateAll(ds)

        End Function

    客户端相关代码:

      Public sc As New Sjfw.Service1Client
      sc.UpdateDataSet(Me.erpDataSet)

    调试时,数据集设计器自动生成的 .DataSet.Designer.vb相关代码段出现错误:

    <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _
             Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")>  _
            Public Property bh() As String
                Get
                    Return CType(Me(Me.tablecp.bhColumn),String)
                End Get
                Set
                    Me(Me.tablecp.bhColumn) = value
                End Set
            End Property

    错误信息:

    用户代码未处理 System.ArgumentNullException
      HResult=-2147467261
      Message=“column”参数不能为空。
    参数名: column
      ParamName=column
      Source=System.Data

    但该数据实际并非空的,保存前验证也无任何问题!

    选择继续运行,仍能正常保存数据,但当把客户端代码改为:

    sc.UpdateCp(Me.erpDataSet.cp)

    调试时,正常运行,但表无任何更新。

    该如何是好呢?


    韩立学







    2015年6月20日 6:37

答案