Results 1 to 3 of 3

Thread: From Excel To MS SQL

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Question From Excel To MS SQL

    Hello,

    I have some problem with automatically exporting data from excel to MS Sql server.

    To get data from excel I use this function:

    VB Code:
    1. Private Function getDataFromXLS(ByVal strFilePath As String) As DataTable
    2.         Try
    3.             Dim strConnectionString As String = String.Empty
    4.  
    5.  
    6.             strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath + ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
    7.             Dim cnCSV As OleDbConnection = New OleDbConnection(strConnectionString)
    8.             cnCSV.Open()
    9.             Dim cmdSelect As OleDbCommand = New OleDbCommand("SELECT * FROM [Book1$]", cnCSV)
    10.             Dim daCSV As OleDbDataAdapter = New OleDbDataAdapter
    11.             daCSV.SelectCommand = cmdSelect
    12.             Dim dtCSV As DataTable = New DataTable
    13.             daCSV.Fill(dtCSV)
    14.  
    15.             cnCSV.Close()
    16.             daCSV = Nothing
    17.             Return dtCSV
    18.         Catch ex As Exception
    19.             Return Nothing
    20.         Finally
    21.         End Try
    22.     End Function
    23.  
    24.  
    25. End Class

    How automatically create and fill table in MS Sql with data from this datatable?

  2. #2
    Member mumick's Avatar
    Join Date
    Apr 2005
    Location
    Milwaukee, WI
    Posts
    35

    Re: From Excel To MS SQL

    why don't you use MS SQL DTS to do it. It will allow you to choose specific colomuns and filtering and then it will create tables automatically for you.
    Good luck
    What boots up must come down.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Re: From Excel To MS SQL

    The idea is that not skilled users may import excel files to DB.

    The interface would be very simple. They'll choose excel file and press Submit.

    Then program must create new table depending on excel columns and import data from it.


    Hope understood what I need.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width