storing dataset

  • Thread starter Thread starter gyoder
  • Start date Start date
G

gyoder

what is the prefered method of storing a dataset to a non-database file.
perhaps a binary file?

thanks
 
what is the prefered method of storing a dataset to a non-database file.
perhaps a binary file?

The CSV file (comma separated values) format is convenient and widely
recognized. In general, it is a flat text file, one record per line,
with values separated by commas and strings enclosed in quotes. See
http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm#FileFormat
for more details.

Many databases can import these files directly with no further effort
on your part except to make sure that the fields in the file
correspond to the columns in the database.
 
i really have no need to import the data into a database. i want to be able
to save/store it and reload it again along with other data. so the file
would contain data from the dataset and also other data.
 
The DataSet is XML, which is rather easy to read. If you are talking local
storage to be used like a database, it would depend on the size, however, as
a huge DataSet would take awhile to load. For local storage, I would
consider some "light" database engine. There are a few open source
implementations that would work.

Without knowing more about the project, that is about all I can offer.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
The CSV file (comma separated values) format is convenient and widely
recognized. In general, it is a flat text file, one record per line,
with values separated by commas and strings enclosed in quotes. See
http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm#FileFormat
for more details.

Many databases can import these files directly with no further effort
on your part except to make sure that the fields in the file
correspond to the columns in the database.

Of course the easiest way is to save it as an XML file - WriteXML(string
fileName) as I recall.
 
Serialization is the way to go. Either XML or binary (assuming you are on
..net 2.0). There is also DataSet.WriteXml/ReadXml pair you might find
convenient.
 
i really have no need to import the data into a database. i want to be able
to save/store it and reload it again along with other data. so the file
would contain data from the dataset and also other data.
(I have taken the liberty of "correcting" your top-posting because
this is the style I prefer)

Converting everything from whatever format to ASCII for storing files
and then back again when reading them is a big pain. However, being
able to easily read the files and so verify that they are being
written correctly or chasing down a tricky bug in finding that the
value you read back is not the same as the value you write can be a
real lifesaver. Also you never know whether, sometime in the future,
you might want to import the data into a database or spreadsheet. I
find that doing the work of making human-readable files is paid back
many times over. You don't have to make them "user friendly"
readable, only "readable if you have the details of what fields are
in what order."

That being said, the simplest way of saving the data is to create a
fixed-length data structure to store all the data and then write and
read binary files just by byte-copying the data structure to the file
and reading it back into the data structure.

Or, I should say, that is the simplest way for me. What is
"preferred" is whatever you can do easily and works without error.
There are no problems provided you are absolutely sure that only your
software is ever going to do both the reading and the writing. If you
ever have to send a file to somebody else for reading and it is a
binary file, you cannot be sure even that the same source code
compiled with a different compiler or even a different version of the
same compiler will produce a program that can read the binary file
unless you take great care in its design. You cannot also be sure
that a file you wrote a few years back with one compiler will be
readable now with recompiled software. The portability factor alone
is worth going with the CSV type file.

Note: in the olden days, it was quite simple: you used printf() to
write each line and sscanf() with the same format statement to read
the lines. It is a little more work now with streams but the same
idea applies; make the stream out and the stream in statements exactly
parallel and it should work.
 
Could you please expand upon "serialization". Perhaps binanry. Im on .net
2.0.

Thanks


Miha Markic said:
Serialization is the way to go. Either XML or binary (assuming you are on
.net 2.0). There is also DataSet.WriteXml/ReadXml pair you might find
convenient.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

gyoder said:
what is the prefered method of storing a dataset to a non-database file.
perhaps a binary file?

thanks
 
Hi,

Here you'll find an example:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=204833&SiteID=1

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

gyoder said:
Could you please expand upon "serialization". Perhaps binanry. Im on .net
2.0.

Thanks


Miha Markic said:
Serialization is the way to go. Either XML or binary (assuming you are on
.net 2.0). There is also DataSet.WriteXml/ReadXml pair you might find
convenient.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

gyoder said:
what is the prefered method of storing a dataset to a non-database file.
perhaps a binary file?

thanks
 
Back
Top