473,387 Members | 1,619 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,387 software developers and data experts.

Making a flat file

JAc
Hey,

it must be very simple but I am struggeling.

I want to make a simple flat file.

I do now (I also tried with string)

foreach(Object obj in collection)
{
recordline = new StringBuilder();
recordline.Capacity = 200;

recordline.append("R01",1,3);
recordline.append("TEST",4,4);
recordline.append(obj.textfield,8,10);

recordline = recordline + "\n"; // New line is it nessecary?

streamwriterCubic.Writeline(recordline);

}
streamwriterCubic.Close.
It don'work. Receive an error on startindex in append (also when I used
Insert). I also tried with a foreach too fill up the recordline witj 200
blanc's. But I think that is not a good idea. There must be something simple.

Thanks for showing me the best way.
Jac
Nov 16 '05 #1
2 1404
Hi Jac,

I think you are getting a runtime error
(System.ArgumentOutOfRangeException?) because the count in your append goes
beyond the character position in the string you are trying to append. For
example, in the first Append, the starting position parameter refers to
"R01", not the StringBuilder. You said start at position 1, which is '0'.
You also specified the third parameter to count 3 characters. Well, there
aren't 3 characters from '0' in "R01" -- only two. Since you already know
the text you want to append, you don't need the Append overload you're
using. Try this:

recordline.Append("R01");

BTW, it helps if you provide code that compiles. ;)

Joe
--
http://www.csharp-station.com

"JAc" <JA*@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hey,

it must be very simple but I am struggeling.

I want to make a simple flat file.

I do now (I also tried with string)

foreach(Object obj in collection)
{
recordline = new StringBuilder();
recordline.Capacity = 200;

recordline.append("R01",1,3);
recordline.append("TEST",4,4);
recordline.append(obj.textfield,8,10);

recordline = recordline + "\n"; // New line is it nessecary?

streamwriterCubic.Writeline(recordline);

}
streamwriterCubic.Close.
It don'work. Receive an error on startindex in append (also when I used
Insert). I also tried with a foreach too fill up the recordline witj 200
blanc's. But I think that is not a good idea. There must be something
simple.

Thanks for showing me the best way.
Jac

Nov 16 '05 #2
In addition to what Joe mentioned:

The StringBuilder.Capacity property does not set the length of the
string. It just sets how much memory that will initially be allocated
for the character data. If the string should become larger than the
capacity during the StringBuilder operations, the capacity will be
increased.

So there is no need to fill the StringBuilder with blanks.

Regards,
Joakim
Nov 16 '05 #3

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

Similar topics

13
by: raykyoto | last post by:
Hi all, I'm sure this is a popular question that comes up every few months here. Indeed, I've looked at some of the past postings, but I would like to ask things differently. Basically, I'm...
1
by: Tim Fierro | last post by:
Hello, I have had many years using flat file databases (File Express from way back) but am now at a company where a relational database is needed and would carry us into the future. Since I...
22
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text...
4
by: Ben | last post by:
So, at my place of employment, we use a national standard to transmit data between certain applications. This standard consists of a fixed width, flat file 4500-some-odd chars wide that contain...
2
by: Neural | last post by:
Hi, I was wondering if anybody knew of any other ways of efficiently parsing a flat file into SQL Server 2000 using C#. The flat files are tab delimited. And the general file size is around 1 GB...
14
by: vunet.us | last post by:
Hi, I would like to use flat file data storage instead of database. Since I am new to it, I am wondering: What text file extension is a safe one to store my data online and how cost- and...
9
by: FFMG | last post by:
In my site I have a config table, (MySQL), with about 30 entries; the data is loaded on every single page load. This is not the only call to the db, (we do a total of about 8 calls to the db). As...
2
by: murthydb2 | last post by:
Hi My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or validation error that occurs inside the db2 sp during...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...

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.