vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Friday, February 3, 2012

Read CSV files store into database or data table


Hi.
Introduction:
Here we discuss about to read CSV file and load into data table or store into database…
Description:

Its very easy methods to read CSV file and store..In many case we use reader to read file then we stored into data table…
Here we directly read the file into data table…Using this techniques..We improve the performance

Code:
String PATHFIL,strQuery;
        PATHFIL = "C:\736.csv"
       
        Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " & System.IO.Path.GetDirectoryName(PATHFIL) & "; Extended Properties = ""Text;HDR=YES;FMT=Delimited""")
        conn.Open()
        strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(PATHFIL) + "]"
        Dim ADAPTER As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(strQuery, conn)
       
        ADAPTER.Fill(DS)
        DT = DS.Tables(0)

Once we got all the data in data table..Then we can do, whatever we want..Either can store in database or do any manipulation….

I hope u spend some worth time …..

0 comments:

Post a Comment