Murray Brown
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
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
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER