Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Create a DataTable from an Excel sheet

Hi

The following code is used to create a DataTable in Eric Moreau's post at
http://emoreau.com/Entries/Articles/2010/12/Using-ADONet-SQL-Bulk-Copy-feature.aspx
I am trying to work out how to create a the same table from a spreadsheet like the one shown in the image
How would I do this?

    Private Function CreateDataSource(ByVal pLargeDataTable As Boolean) As DataTable
        Dim dt As New DataTable("Person")
        With dt
            .Columns.Add("ID", GetType(Integer))
            .Columns.Add("FirstName", GetType(String))
            .Columns.Add("LastName", GetType(String))

            'Add rows
            .LoadDataRow(New Object() {-1, "Joe", "Dalton"}, True)
            .LoadDataRow(New Object() {-2, "Jack", "Dalton"}, True)
            .LoadDataRow(New Object() {-3, "Willam", "Dalton"}, True)
            .LoadDataRow(New Object() {-4, "Averell", "Dalton"}, True)

            If pLargeDataTable Then
                Dim intID As Integer = 5
                Do While intID <= 100000
                    .LoadDataRow(New Object() {intID * -1, "FN" + intID.ToString, "Dalton"}, True)
                    intID += 1
                Loop
            End If
        End With

        Return dt
    End Function

User generated image
Visual Basic.NET

Avatar of undefined
Last Comment
Murray Brown
ASKER CERTIFIED SOLUTION
Avatar of Phillip Burton
Phillip Burton

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Murray Brown
Murray Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Yes. Thanks
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo