limits for filestreams (C#)

G

gloria

So I am writing data from a datastream to a filestream. The count of
rows in the datastream is 416. I count as I write to the filestream
and again I get 416. However, when I open the file, there are only 392
rows. What happened? Where are my missing rows? Are there limits to
using filestreams?

Thoughts?

--gloria
-------------------------------------

StreamWriter outputfileSW = File.CreateText(filenameStr);

string extractpartsStr = "select ..." ;

try
{
OleDbConnection extractpartsCN = new
OleDbConnection(extractbpmClass.strConn);

OleDbDataAdapter extractpartsDA = new
OleDbDataAdapter(extractpartsStr,extractpartsCN);
DataSet extractpartsDS = new DataSet();
extractpartsDA.Fill(extractpartsDS);

string subinvStr, partnumStr, descStr, serializedflagStr,
statusStr, hscodeStr;
string cooStr, newpartflagStr, BAXLineStr;
string tab = "\t";
int serializedInt, newpartInt;

DataTable build888Table = extractpartsDS.Tables[0];

int totalrows = build888Table.Rows.Count;
int countrows = 0;

foreach(DataRow build888Row in build888Table.Rows)
{
subinvStr = build888Row["SubInv"].ToString();
partnumStr = build888Row["PartNum"].ToString();
descStr = build888Row["PartDescr"].ToString();
serializedflagStr = build888Row["SerialFlag"].ToString();
statusStr = build888Row["Status"].ToString();
hscodeStr = build888Row["HSCode"].ToString();
cooStr = build888Row["COO"].ToString();
newpartflagStr = build888Row["NPFlag"].ToString();

if (serializedflagStr == "False")
serializedInt = 1;
else
serializedInt = 0;

if (newpartflagStr == "False")
newpartInt = 1;
else
newpartInt = 0;

BAXLineStr = subinvStr + tab + partnumStr + tab + descStr + tab +
//13 tabs
tab + tab + tab + tab + tab + tab +
tab + tab + tab + tab + tab + tab +
tab +
serializedInt + tab + statusStr + tab +
tab +
hscodeStr + tab + cooStr + tab +
//37 tabs
tab + tab + tab + tab + tab + tab +
tab + tab + tab + tab + tab + tab +
tab + tab + tab + tab + tab + tab +
tab + tab + tab + tab + tab + tab +
tab + tab + tab + tab + tab + tab +
tab + tab + tab + tab + tab + tab +
tab +
newpartInt;

outputfileSW.WriteLine(BAXLineStr);
countrows = countrows+1;
}

Console.WriteLine("\ttotalrows: " + totalrows);
Console.WriteLine("\n\tcountrows: " + countrows);
 
J

Jon Skeet [C# MVP]

gloria said:
So I am writing data from a datastream to a filestream. The count of
rows in the datastream is 416. I count as I write to the filestream
and again I get 416. However, when I open the file, there are only 392
rows. What happened? Where are my missing rows? Are there limits to
using filestreams?

You're not closing the writer as far as I can see, which means it might
not get flushed. You should use a using statement to make sure that the
StreamWriter gets closed whatever happens.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top