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!

Categories

Importing excel file to database

G.ManivannanG.Manivannan Posts: 43Member
Hi,
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.

Comments

  • 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

    [Code]
    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)
    Next

    i += 1

    Loop

    FileClose(FF)

    '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
    [/Code]
Sign In or Register to comment.