Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
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
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.