Solved

VB.net get data table into SQL

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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.

830 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