473,403 Members | 2,284 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,403 software developers and data experts.

Read from a textfile and save in database

Hello ALL,
I need to read data from a .txt file and save this data in a sql server
database table.
The .txt file format like this:
-----------------------------------------------------------
01851L. D. DISTRIBUIDORA DE S. M. LTDA L. D. DISTRIBUIDORA
73765034000140102622574 10008AV. ANHANGUERA,
02469NICOLAS BARREIRA GONZALES NICOLAS BARREIRA
56599749000151336206241110 10013RUA SISA, 465

And the I need to pass to database table like this:
Table Customers
-------------------------------------------
IdCustomer - 01851
FullName - L. D. DISTRIBUIDORA DE S. M. LTDA
ShortName - L. D. DISTRIBUIDORA
CurrNo - 73765034000140102622574
SpNo - 10008
Address - AV. ANHANGUERA
Well, I know I guess use StreamReader to read the .txt file no?
StreaReader x = new StreamReader("C:\\data.txt");
But I need some help with the logic, the loop, to do this code.

Anyboy help me?

Thanks in advance and sorry my English.

Fernando Lopes
São Paulo - Brasil
Nov 17 '05 #1
7 1747
fix your date then maybe someone will help you first..
"[ F e r n a n d o L o p e s ]" <lo****************@spacnet.com.br> wrote in
message news:eM**************@tk2msftngp13.phx.gbl...
Hello ALL,
I need to read data from a .txt file and save this data in a sql server
database table.
The .txt file format like this:
-----------------------------------------------------------
01851L. D. DISTRIBUIDORA DE S. M. LTDA L. D. DISTRIBUIDORA
73765034000140102622574 10008AV. ANHANGUERA,
02469NICOLAS BARREIRA GONZALES NICOLAS BARREIRA
56599749000151336206241110 10013RUA SISA, 465

And the I need to pass to database table like this:
Table Customers
-------------------------------------------
IdCustomer - 01851
FullName - L. D. DISTRIBUIDORA DE S. M. LTDA
ShortName - L. D. DISTRIBUIDORA
CurrNo - 73765034000140102622574
SpNo - 10008
Address - AV. ANHANGUERA
Well, I know I guess use StreamReader to read the .txt file no?
StreaReader x = new StreamReader("C:\\data.txt");
But I need some help with the logic, the loop, to do this code.

Anyboy help me?

Thanks in advance and sorry my English.

Fernando Lopes
São Paulo - Brasil

Nov 17 '05 #2
The logic is you read a line and chop it out according to the position of
each type of data. For LDCustomer, you will get substring of 0 to 4 etc..

"Brian Henry" <br******@adelphia.net> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
fix your date then maybe someone will help you first..
"[ F e r n a n d o L o p e s ]" <lo****************@spacnet.com.br> wrote in message news:eM**************@tk2msftngp13.phx.gbl...
Hello ALL,
I need to read data from a .txt file and save this data in a sql server
database table.
The .txt file format like this:
-----------------------------------------------------------
01851L. D. DISTRIBUIDORA DE S. M. LTDA L. D. DISTRIBUIDORA
73765034000140102622574 10008AV. ANHANGUERA,
02469NICOLAS BARREIRA GONZALES NICOLAS BARREIRA
56599749000151336206241110 10013RUA SISA, 465

And the I need to pass to database table like this:
Table Customers
-------------------------------------------
IdCustomer - 01851
FullName - L. D. DISTRIBUIDORA DE S. M. LTDA
ShortName - L. D. DISTRIBUIDORA
CurrNo - 73765034000140102622574
SpNo - 10008
Address - AV. ANHANGUERA
Well, I know I guess use StreamReader to read the .txt file no?
StreaReader x = new StreamReader("C:\\data.txt");
But I need some help with the logic, the loop, to do this code.

Anyboy help me?

Thanks in advance and sorry my English.

Fernando Lopes
São Paulo - Brasil


Nov 17 '05 #3
I would use StringReader to read the line, not substring. Cleaner, i
believe.

"zPaul" <~p****@phnip.com> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
The logic is you read a line and chop it out according to the position of
each type of data. For LDCustomer, you will get substring of 0 to 4 etc..

"Brian Henry" <br******@adelphia.net> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
fix your date then maybe someone will help you first..
"[ F e r n a n d o L o p e s ]" <lo****************@spacnet.com.br>
wrote in
message news:eM**************@tk2msftngp13.phx.gbl...
Hello ALL,
I need to read data from a .txt file and save this data in a sql server database table.
The .txt file format like this:
-----------------------------------------------------------
01851L. D. DISTRIBUIDORA DE S. M. LTDA L. D. DISTRIBUIDORA
73765034000140102622574 10008AV. ANHANGUERA,
02469NICOLAS BARREIRA GONZALES NICOLAS BARREIRA
56599749000151336206241110 10013RUA SISA, 465

And the I need to pass to database table like this:
Table Customers
-------------------------------------------
IdCustomer - 01851
FullName - L. D. DISTRIBUIDORA DE S. M. LTDA
ShortName - L. D. DISTRIBUIDORA
CurrNo - 73765034000140102622574
SpNo - 10008
Address - AV. ANHANGUERA
Well, I know I guess use StreamReader to read the .txt file no?
StreaReader x = new StreamReader("C:\\data.txt");
But I need some help with the logic, the loop, to do this code.

Anyboy help me?

Thanks in advance and sorry my English.

Fernando Lopes
São Paulo - Brasil



Nov 17 '05 #4
are you using access or sql server?

if sql server you can do a bulk insert with bcp

/Lasse
"[ F e r n a n d o L o p e s ]" <lo****************@spacnet.com.br> wrote in
message news:eM**************@tk2msftngp13.phx.gbl...
Hello ALL,
I need to read data from a .txt file and save this data in a sql server
database table.
The .txt file format like this:
-----------------------------------------------------------
01851L. D. DISTRIBUIDORA DE S. M. LTDA L. D. DISTRIBUIDORA
73765034000140102622574 10008AV. ANHANGUERA,
02469NICOLAS BARREIRA GONZALES NICOLAS BARREIRA
56599749000151336206241110 10013RUA SISA, 465

And the I need to pass to database table like this:
Table Customers
-------------------------------------------
IdCustomer - 01851
FullName - L. D. DISTRIBUIDORA DE S. M. LTDA
ShortName - L. D. DISTRIBUIDORA
CurrNo - 73765034000140102622574
SpNo - 10008
Address - AV. ANHANGUERA
Well, I know I guess use StreamReader to read the .txt file no?
StreaReader x = new StreamReader("C:\\data.txt");
But I need some help with the logic, the loop, to do this code.

Anyboy help me?

Thanks in advance and sorry my English.

Fernando Lopes
São Paulo - Brasil

Nov 17 '05 #5
Sorry about the date man.
I change to test some functions in one program and forgot.

"Brian Henry" <br******@adelphia.net> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
fix your date then maybe someone will help you first..
"[ F e r n a n d o L o p e s ]" <lo****************@spacnet.com.br> wrote in message news:eM**************@tk2msftngp13.phx.gbl...
Hello ALL,
I need to read data from a .txt file and save this data in a sql server
database table.
The .txt file format like this:
-----------------------------------------------------------
01851L. D. DISTRIBUIDORA DE S. M. LTDA L. D. DISTRIBUIDORA
73765034000140102622574 10008AV. ANHANGUERA,
02469NICOLAS BARREIRA GONZALES NICOLAS BARREIRA
56599749000151336206241110 10013RUA SISA, 465

And the I need to pass to database table like this:
Table Customers
-------------------------------------------
IdCustomer - 01851
FullName - L. D. DISTRIBUIDORA DE S. M. LTDA
ShortName - L. D. DISTRIBUIDORA
CurrNo - 73765034000140102622574
SpNo - 10008
Address - AV. ANHANGUERA
Well, I know I guess use StreamReader to read the .txt file no?
StreaReader x = new StreamReader("C:\\data.txt");
But I need some help with the logic, the loop, to do this code.

Anyboy help me?

Thanks in advance and sorry my English.

Fernando Lopes
São Paulo - Brasil


Nov 17 '05 #6
Well, ok but, how can I do the loop.
I need help to write the logical code for get the data from de .txt file and
insert into the database
Is something like this?

StreamReader file = new StreamReader("C:\\data.txt");
for (int i=0;i<file.Lenght;i++)
{
Here i don´t know what am i do!!
}

Thanks.

Fernando Lopes
"zPaul" <~p****@phnip.com> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
The logic is you read a line and chop it out according to the position of
each type of data. For LDCustomer, you will get substring of 0 to 4 etc..

"Brian Henry" <br******@adelphia.net> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
fix your date then maybe someone will help you first..
"[ F e r n a n d o L o p e s ]" <lo****************@spacnet.com.br>
wrote in
message news:eM**************@tk2msftngp13.phx.gbl...
Hello ALL,
I need to read data from a .txt file and save this data in a sql server database table.
The .txt file format like this:
-----------------------------------------------------------
01851L. D. DISTRIBUIDORA DE S. M. LTDA L. D. DISTRIBUIDORA
73765034000140102622574 10008AV. ANHANGUERA,
02469NICOLAS BARREIRA GONZALES NICOLAS BARREIRA
56599749000151336206241110 10013RUA SISA, 465

And the I need to pass to database table like this:
Table Customers
-------------------------------------------
IdCustomer - 01851
FullName - L. D. DISTRIBUIDORA DE S. M. LTDA
ShortName - L. D. DISTRIBUIDORA
CurrNo - 73765034000140102622574
SpNo - 10008
Address - AV. ANHANGUERA
Well, I know I guess use StreamReader to read the .txt file no?
StreaReader x = new StreamReader("C:\\data.txt");
But I need some help with the logic, the loop, to do this code.

Anyboy help me?

Thanks in advance and sorry my English.

Fernando Lopes
São Paulo - Brasil



Nov 17 '05 #7
Hello Lasse.
Sorry but, what is a bulk insert with bcp?

Thanks

Fernando Lopes

"Lasse Edsvik" <la***@nospam.com> wrote in message
news:uF**************@TK2MSFTNGP12.phx.gbl...
are you using access or sql server?

if sql server you can do a bulk insert with bcp

/Lasse
"[ F e r n a n d o L o p e s ]" <lo****************@spacnet.com.br> wrote in message news:eM**************@tk2msftngp13.phx.gbl...
Hello ALL,
I need to read data from a .txt file and save this data in a sql server
database table.
The .txt file format like this:
-----------------------------------------------------------
01851L. D. DISTRIBUIDORA DE S. M. LTDA L. D. DISTRIBUIDORA
73765034000140102622574 10008AV. ANHANGUERA,
02469NICOLAS BARREIRA GONZALES NICOLAS BARREIRA
56599749000151336206241110 10013RUA SISA, 465

And the I need to pass to database table like this:
Table Customers
-------------------------------------------
IdCustomer - 01851
FullName - L. D. DISTRIBUIDORA DE S. M. LTDA
ShortName - L. D. DISTRIBUIDORA
CurrNo - 73765034000140102622574
SpNo - 10008
Address - AV. ANHANGUERA
Well, I know I guess use StreamReader to read the .txt file no?
StreaReader x = new StreamReader("C:\\data.txt");
But I need some help with the logic, the loop, to do this code.

Anyboy help me?

Thanks in advance and sorry my English.

Fernando Lopes
São Paulo - Brasil


Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: R. van Laake | last post by:
Hi, I have a database with information of my users, lets say their date of birth. I want them to be able to go to my site, and login with a username and password, after which they get to see...
1
by: tim | last post by:
I have a multi-dimensional byte array, private someArray(,,) as byte and it's huge redim someArray(100,640,480,3) after populating the array, I write it to a text file to save it. (so I don't...
8
by: andreas | last post by:
A textfile can have different formats like ANSI,UTF8, Unicode ... Using streamreader for a textfile can have different results for chars like é,à,è....depending of the fileformat. To solve this...
1
by: Eric | last post by:
I wrote a program which read emails from a textfile. I save these emails from inbox. I need hlep how to i read the body of an email from a text file. Dim fso, fil, ts, sContents Set fso =...
9
by: Justme | last post by:
Novice programmer needs help with using fgets to read and ignore the first two lines of a file. I've gone thru the previous posting regarding fgets, but none of them seems to help my situation. I...
2
by: RaviRajhulk | last post by:
I am trying to read folder and subfolder and print their name into a text file.I am able to read the folder and its content and write it to the textfile but I am not able to read the content of the...
0
by: Snoze | last post by:
Hello, I'm trying to make an application with C# that writes and reads some lines of a text file, but I want to read one specific line and save the text in a string variable. And the inverse...
3
by: Raymond Chiu | last post by:
Dear all, Now I have the simple task to read text file line by line into database (SQL Server 2000). If the text file is divided into different fields according to the number of characters,...
3
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I am trying to loop a Textfile. This Textfile is located on a shared drive and it is used by another process. When I try to read it I get an exeption: The process cannot access the...
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: 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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.