By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Inserting values from text file into a table

P: 44
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
Expand|Select|Wrap|Line Numbers
  1.     Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
  3.         Dim tbl As New DataTable("mytable")
  4.         tbl.Columns.Add("col1", GetType(String))
  6.         Dim sFilename As String = "C:\Users\User\Desktop\test.txt"
  7.         Dim myStream As System.IO.StreamReader = New System.IO.StreamReader(sFilename)
  8.         Dim line As String
  9.         Dim aRow As DataRow
  10.         Do
  11.             line = myStream.ReadLine()
  12.             MsgBox(line)
  13.             If line Is Nothing Then
  14.                 Exit Do
  15.             End If
  16.             Dim sAry As String() = Split (line, ";")           
  17.            aRow = tbl.NewRow            
  18.             aRow(0) = sAry(0)
  19.             tbl.Rows.Add(aRow)
  20.         Loop
  21.         myStream.Close()
  22.         For Each aRow In tbl.Rows
  23.             Console.WriteLine("{0}", aRow(0))
  25.         Next
  27.     End Sub
  28. End Class
Mar 21 '12 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 100+
P: 465
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?
Mar 22 '12 #2

P: 44
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.
Mar 23 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.