1 Replies - 517 Views - Last Post: 28 June 2013 - 09:14 AM Rate Topic: -----

#1 fanglign  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 48
  • Joined: 24-June 13

text file to access

Posted 28 June 2013 - 09:11 AM

Dim OLEcmd As New OleDbCommand

        Dim OLEconnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\111411H\My Documents\data.accdb;")
        'Dim OLECmd As New OleDbCommand("SELECT * INTO [StudentsData] FROM [Text;Database=J:\FYP;].[SEG1.txt]", OLEconnection)
        OLEcmd.Connection = OLEconnection





        'dgv columns
        DataGridView1.ColumnCount = 5
        DataGridView1.Columns(0).Name = "School"
        DataGridView1.Columns(1).Name = "Campus"
        DataGridView1.Columns(2).Name = "AdminNo"
        DataGridView1.Columns(3).Name = "ModuleCode"
        DataGridView1.Columns(4).Name = "ModuleGrp"

        Dim i, j As Integer
        For i = 0 To j
            'read lines from text file
            For Each line As String In System.IO.File.ReadAllLines("J:\FYP\SEG1.txt")


                Dim arrdata() As String
                arrdata = line.Split(vbTab)

                Dim School As String = arrdata(0)
                Dim Campus As String = arrdata(1)
                Dim AdminNo As String = arrdata(2)
                Dim ModuleCode As String = arrdata(3)
                Dim ModuleGrp As String = arrdata(4)


                OLEcmd.CommandText = "Insert into Table1(School, Campus, AdminNo, ModuleCode, ModuleGrp) values ('" & arrdata(0) & "', '" & arrdata(1) & "', '" & arrdata(2) & "', '" & arrdata(3) & "', '" & arrdata(4) & "')"
                ReDim Preserve arrdata(i)
            Next

        Next

        OLEconnection.Open()
        OLEcmd.ExecuteNonQuery()
        OLEconnection.Close()



anyone tell me whats wrong with this? i want to read text file to access database. its only inserting one line.
why is that so?
Thanks in advance!

This post has been edited by modi123_1: 28 June 2013 - 09:13 AM
Reason for edit:: highlight the text and just click the 'code' button in the text editor


Is This A Good Question/Topic? 0
  • +

Replies To: text file to access

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9568
  • View blog
  • Posts: 36,224
  • Joined: 12-June 08

Re: text file to access

Posted 28 June 2013 - 09:14 AM

I would figure having your 'ExecuteNonQuery' outside of the forloop would be a bad idea if you want it to execute each time the for loop.. well.. loops.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1