Mass update of a strongly typed dataset?

Can I perform a batch update on a strongly typed dataset? UpdateBatchSize does not seem to be a parameter after creating a strongly typed dataset.

+3
source share
1 answer

Have you tried adding this property to the DataAdapter? Extend the auto-generated adapter class with the UpdateBatchSize property, for example ( not yet verified ):

Namespace DataSet1TableAdapters
    Partial Public Class AddressTableAdapter
        Public Property UpdateBatchSize() As Integer
            Get
                Return Me.Adapter.UpdateBatchSize
            End Get
            Set(ByVal value As Integer)
                Me.Adapter.UpdateBatchSize = value
                If value <> 1 Then
                    Me.Adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None
                    Me.Adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None
                    Me.Adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None
                Else
                    Me.Adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord
                    Me.Adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord
                    Me.Adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord
                End If
            End Set
        End Property
    End Class
End Namespace

autogenerated designer.cs/vb , , , , designer. , .

#

namespace DataSet1TableAdapters
{
    public partial class AddressTableAdapter
    {
        public int UpdateBatchSize {
            get { return this.Adapter.UpdateBatchSize; }
            set {
                this.Adapter.UpdateBatchSize = value;
                if (value != 1) {
                    this.Adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
                    this.Adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
                    this.Adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None;
                } else {
                    this.Adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
                    this.Adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
                    this.Adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
                }
            }
        }
    }
}

, , , , .

: this , UpdatedRowSource .

:

Dim stopWatch As New Stopwatch
Dim da As New DataSet1TableAdapters.AddressTableAdapter
Dim tblAllAdresses As New DataSet1.AddressDataTable
Dim tsBS1, tsBS0 As TimeSpan

da.Fill(tblAllAdresses)

da.UpdateBatchSize = 1
For Each adrr As DataSet1.AddressRow In tblAllAdresses
    adrr.ModifiedDate = Date.Now
Next
stopWatch.Start()
Dim addressesChanged As Int32 = da.Update(tblAllAdresses)
stopWatch.Stop()
tsBS1 = stopWatch.Elapsed

da.UpdateBatchSize = 0 '0 means maximum server can handle'
For Each adrr As DataSet1.AddressRow In tblAllAdresses
    adrr.ModifiedDate = Date.Now
Next
stopWatch.Restart()
addressesChanged = da.Update(tblAllAdresses)
stopWatch.Stop()
tsBS0 = stopWatch.Elapsed

Console.WriteLine("tsBS1: " & tsBS1.Minutes & ":" & tsBS1.Seconds & ":" & tsBS1.Milliseconds) '12 seconds'
Console.WriteLine("tsBS0: " & tsBS0.Minutes & ":" & tsBS0.Seconds & ":" & tsBS0.Milliseconds) '9 seconds(on localhost!)'
+3

All Articles