1

我有一个使用 SP 进行所有操作的表适配器。填充和更新中的一个字段是时间戳(转换为 bigint 并命名为“VersionNo”),我在更新期间用于并发检查。由于某种原因,该字段和另一个名为“名称”的字段在表适配器中都设置为只读,所以每次我更改我的 SP 列并更新适配器时,它们都会被设置为只读并且我的更新失败。我必须记住将它们更改为 ReadOnly = False。

谁能解释为什么将它们设置为只读以及如何修复它,这样我每次更改数据库架构时都不必手动更新它们?这是失败的地方:

<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _
 Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")>  _
Public Property VersionNo() As Long
    Get
        Try 
            Return CType(Me(Me.tableShipping_Invoice.VersionNoColumn),Long)
        Catch e As Global.System.InvalidCastException
            Throw New Global.System.Data.StrongTypingException("The value for column 'VersionNo' in table 'Shipping_Invoice' is DBNull.", e)
        End Try
    End Get
    Set
        Me(Me.tableShipping_Invoice.VersionNoColumn) = value
    End Set
End Property

更新过程中甚至没有使用“名称”列,所以我不知道为什么它甚至抱怨:

<UpdateParameters>
                <asp:ControlParameter ControlID="dvInvoice$txtVersionNo" PropertyName="Text" Name="VersionNo" Type="Int64" />
                <asp:ControlParameter ControlID="dvInvoice$txtTripNo" PropertyName="Text" Name="TripNo" Type="String" />
                <asp:ControlParameter ControlID="dvInvoice$ddLineTypes" PropertyName="SelectedValue" Name="TypeID" Type="Int32" />
                <asp:ControlParameter ControlID="dvInvoice$ddVendors" PropertyName="SelectedValue" Name="VendorID" Type="Int32" />
                <asp:ControlParameter ControlID="dvInvoice$txtInvNo" PropertyName="Text" Name="InvNo" Type="String" />
                <asp:ControlParameter ControlID="dvInvoice$txtInvAmount"  PropertyName="Text" Name="InvAmount" Type="Decimal" />
                <asp:ControlParameter ControlID="dvInvoice$txtInvDate" PropertyName="Text" Name="InvDate" Type="DateTime" />
                <asp:ControlParameter ControlID="dvInvoice$txtID" PropertyName="Text" Name="ID" Type="Int32" />
            </UpdateParameters>

BLL 代码

    <System.ComponentModel.DataObjectMethodAttribute _
(System.ComponentModel.DataObjectMethodType.Update, True)> _
    Public Function UpdateInvoiceOC( _
                               TripNo As String, _
                               TypeID As Integer, _
                               VendorID As Integer, _
                               InvNo As String, _
                               InvAmount As Decimal, _
                               InvDate As Date, _
                               ID As Integer, _
                               VersionNo As Long _
                               ) As Boolean

        'STEP 1: Read in the current database product information
        Dim invoices As WolfShipping.Shipping_InvoiceDataTable = Adapter.GetInvoicesByInvoiceID(ID)
        If invoices.Count = 0 Then
            Return False
        End If
        Dim invoice As WolfShipping.Shipping_InvoiceRow = invoices(0)



        ' invoice.trip contains original values and will be udpated with new value
        invoice.TripNo = TripNo
        invoice.TypeID = TypeID
        invoice.VendorID = VendorID
        invoice.InvNo = InvNo
        invoice.InvAmount = InvAmount
        invoice.InvDate = InvDate
        invoice.ID = ID
        invoice.VersionNo = VersionNo
        Dim rowsAffected As Integer = Adapter.Update(invoice)
        ' Return true if precisely one row was updated, otherwise false
        Return rowsAffected = 1



    End Function
4

0 回答 0