Home All Groups Group Topic Archive Search About

limits for filestreams (C#)

Author
17 Feb 2005 9:06 PM
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);
Author
17 Feb 2005 9:16 PM
Jon Skeet [C# MVP]
gloria <gurba***@gmail.com> wrote:
> 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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Are all your drivers up to date? click for free checkup

Author
17 Feb 2005 11:08 PM
gloria
That was my problem.  Thanks!

Bookmark and Share