Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net get data table into SQL

Posted on 2014-11-25
2
Medium Priority
?
269 Views
Last Modified: 2014-11-26
Hi

I am using the following code to create a Data Table from an Excel spreadsheet
What VB.net code would I use to get the Data Table into a SQL database as a new table?

    Public Shared Function GetExcelDataTable(ByVal FileName As String, ByVal TableName As String) As DataTable
        Try
            Dim strPath As String = "C:/Test.xls"
            Dim ds As New DataSet()
            Dim sConnectionString As [String] = ("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=") + strPath & "; " & "Extended Properties=Excel 8.0;"

            Dim objConn As New OleDbConnection(sConnectionString)
            objConn.Open()
            Dim objCmdSelect As New OleDbCommand("SELECT * FROM [" & TableName & "] where IsActive = 1", objConn)
            Dim objAdapter1 As New OleDbDataAdapter()
            objAdapter1.SelectCommand = objCmdSelect
            objAdapter1.Fill(ds)
            objConn.Close()
            Return ds.Tables(0)
        Catch ex As Exception
            'Log your exception here.//
            Return DirectCast(Nothing, DataTable)
        End Try
    End Function
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40465300
Try inserting after SELECT * and before FROM the words

INSERT INTO nameoftable
0
 

Author Closing Comment

by:Murray Brown
ID: 40467296
Thanks
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question