Importing excel file to database - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Importing excel file to database

G.ManivannanG.Manivannan Posts: 43Member
I have one Excel csv format file consists of custermer address info.
I want to import this file to Ms access database by taking the header as datafield by using VB.Net 2005. please help me to solve this problem.
G.Manivannan, M.Sc.,[it],
VBA Programmer,
AKUVA Infotech, Bangalore.


  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    This function will load your CSV file into memory
    All you need to do is write the code to get it into your DB

    Private Sub LoadEXCELinMemory()

    'This will set FF = 1 in most cases
    Dim FF As Integer = FreeFile()
    'To break each line into first
    Dim S() As String
    'Create a String Array to split each line of
    'the config file into
    Dim Str(,) As String
    'Create a temp String to grab the full line into
    Dim TempStr As String
    'Create an integer to keep track of what rows
    'While ReDimming Str(,)
    Dim i As Integer = 0
    'Define the applications path
    Dim AppPath As String = Application.StartupPath
    If AppPath.Substring(AppPath.Length - 1) <> "" Then AppPath &= ""

    'Open File with FF as the reference number
    'Can change the filepath to whatever you need
    FileOpen(FF, AppPath & "test.csv", OpenMode.Input)

    Do While Not EOF(FF)

    Input(FF, TempStr)

    S = TempStr.Split(",")

    ReDim Preserve Str(i, S.Length)

    For h As Integer = 0 To S.Length
    Str(i, h) = S(h)

    i += 1



    'now Everything that was in your CSV file is in memory in the STR object
    'If you Dim STR in a Module (making it Global) you can
    'write a new function that then puts that information into a Database
    'Hope this helps

    End Sub
Sign In or Register to comment.