Solved

VB.net get data table into SQL

Posted on 2014-11-25
2
265 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 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

622 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