Inserting values from text file into a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 315hughes
    New Member
    • Nov 2011
    • 44

    Inserting values from text file into a table

    Hi i am trying to read from a text file and enter this into a table.The text file contains just 3 didget numbers sepearted by a line to distingues a new number. The table consists of 2 columns called ID (which is auto increment PK) and ISBN. The table is called IntTable in a database called book.mdf. I have found some code which i need to change to accumplish this task.Can someone direct me as to what i should be trying to change,add etc i would be very greatful. I am extremly new to all of VB,ASP and using Visual Studio 2010 so please bare with me if i ask what you may percieve as silly questions. Thanks in advance. Below is the code which i presume needs changing
    Code:
        Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
    
            Dim tbl As New DataTable("mytable")
            tbl.Columns.Add("col1", GetType(String))
    
            Dim sFilename As String = "C:\Users\User\Desktop\test.txt"
            Dim myStream As System.IO.StreamReader = New System.IO.StreamReader(sFilename)
            Dim line As String
            Dim aRow As DataRow
            Do
                line = myStream.ReadLine()
                MsgBox(line)
                If line Is Nothing Then
                    Exit Do
                End If
                Dim sAry As String() = Split (line, ";")           
               aRow = tbl.NewRow            
                aRow(0) = sAry(0)
                tbl.Rows.Add(aRow)
            Loop
            myStream.Close()
            For Each aRow In tbl.Rows
                Console.WriteLine("{0}", aRow(0))
    
            Next
    
        End Sub
    End Class
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    So if I'm understanding you correctly you found some code online and want someone to fix it to do what you need it to do?

    Comment

    • 315hughes
      New Member
      • Nov 2011
      • 44

      #3
      im not expecting anyone to fix or give me the code at all. i am asking for some directions, or any help to push me in the direction of what i need to learn. i understand that the code i have given reads line by line from my test.txt file, it distinquishes new parts by a ; it stores it in an array and that it can enter it into a table. But i am not sure where i need to begin adding my table/column details etc so i would appreciate any help. Sorry if the question came across wrong.

      Comment

      Working...