0

As the question says, how can I add multiple rows to a datatable in vb.net? I mean, without looping. F. e. I have an array of datarows and I can then write: dt.Rows.Add(rowarray).

Is this possible? I have searched the net, but found everywhere just looping (or I used the wrong search words).

1
  • Create an array of DataRow's and then add them to the DataTable. What have you tried first? Commented Nov 24, 2014 at 18:57

1 Answer 1

1

I don't think it's possible - DataRowCollection doesn't seem to have anything like AddRange to hide the looping, although I suppose you could write your own extension method:

Imports System.Runtime.CompilerServices

Module MyExtensions

    <Extension>
    Public Sub AddRange(existing As DataRowCollection, newRows As IEnumerable(Of DataRow))
        For Each row In newRows
            existing.Add(row)
        Next
    End Sub

End Module

And use that in your code:

dt.Rows.AddRange(rowarray)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.