473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1.     Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
  2.  
  3.         Dim tbl As New DataTable("mytable")
  4.         tbl.Columns.Add("col1", GetType(String))
  5.  
  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))
  24.  
  25.         Next
  26.  
  27.     End Sub
  28. End Class
Mar 21 '12 #1
2 3368
PsychoCoder
465 Expert Mod 256MB
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
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

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

Similar topics

3
by: Dynamo | last post by:
Hi all I want to save the contents of a textarea within my webform as a text file .txt on my webserver. In addition, I want to save it with the same file name as the next autoincrement number in...
5
by: Fawke101 | last post by:
Hi there, I am new to ASP and i have really only been exposed to getting data from a SQL database and displaying it. I want to include a page in my application (like a form in Access i guess)...
1
by: pmud | last post by:
I have an ASP.NET web application using C# code. I am trying to insert values from a web form into an SQL database. I am using SQL COMMAND object for this. I need to know HOW TO INSERT THE RADIO...
1
by: redneck_kiwi | last post by:
I am attempting to import data from a text file. There are many records to be imported and the raw file format is: "1 |010-5502-502 |16H1-7-3 |CONTACT, ELECTRICAL, 7/8in. ...
2
by: ezelasky | last post by:
We are using the bcp utility (via APIs) to export data from a SQL table in a fixed format text file. BCP is inserting spaces for a field if the field contains a NULL. This is fine with us except...
3
by: Art at ABE Computer Consultants | last post by:
I'm missing something really simple, I'm sure. I have a form to be filled in. The operator choosed a plant species (the botanical name) from a list in a combo box. (The lookup table is populated...
0
by: hellosibba | last post by:
Hi i am trying to use text file to write a value as soon as there is any update/insert into a table. for that i am using a text file and made a linked server relation with it..... and inserting...
3
by: wenggarcia | last post by:
please help me.. kindly see if what's wrong with my code below.. im trying to insert values in a table on my database but the query returned as failed. html code -my input page <form...
4
by: praveena mani | last post by:
how to insert values in this table for these two timestamps??? create table s_details( SELECT_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, TITLE varchar(4) NOT NULL, FIRST_NAME varchar(20)...
1
by: Kaitsu | last post by:
How can I get data from table to text-file by SQL-commands, for example SELECT * FROM Table. Result to text-file Table.txt.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.