Solved

VB.net get data table into SQL

Posted on 2014-11-25
2
255 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:murbro
2 Comments
 
LVL 24

Accepted Solution

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

INSERT INTO nameoftable
0
 

Author Closing Comment

by:murbro
ID: 40467296
Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

803 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