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

Exporting A DataSet - Recommendations?

I'm re-writing an application in C# that was originally written in
Delphi 7. The heart of the application is a DataSet displayed in a
DataGrid.

One of the main functions of the previous application was to save the
data to a file (it was XML, but the format is unimportant) that can be
re-loaded into the DataSet at a later time. (The reason for this was
that the queries which populate the DataSet can take a while to run, and
people wanted a way to just quickly load some "close enough to
up-to-date" data to do some quick work.)

Also, the DataSet (which consists of only one DataTable) could be
exported to a few other formats, such as comma-delimited or tab-delimited.

Can anyone recommend a good way of doing this? I Google around on the
subject, and find lots of articles explaining why exporting to XML is
good, but little explanation on ways of doing it. I did find something
that looked promising at
http://codebetter.com/blogs/brendan..../27/12229.aspx
but it seems to rely heavily on being a web application and I guess I'm
just not familiar enough to convert it to WinForms.

Does anyone have any recommendations for this? If I could just find
something that will Save/Load a DataSet to/from XML, and save a DataSet
to comma/tab-delimited, Excel, etc. that would be great. It doesn't
even all have to be the same tool.
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Jun 26 '06 #1
3 2029
das
As far as Exporting a DataSet to a XML file, simply use:

myDataSet.WriteXml(xmlWriter) //xmlWriter of type: StreamWriter

Vice versa for Reading XML document into a DataSet

myDataSet.ReadXml(xmlDocument) // You might have to read in the schema
for this xml

For Delimited files, first get a DataRow object containing all the data
in the table and loop throug to build a delimited file.

DataRow[] myDataRows = myDataSet.Tables[0].Select();
foreach(DataRow fRow in myDataRows)
{
......
}

May be there are better approaches, but this is what I have used in the
past.

Adios
Does anyone have any recommendations for this? If I could just find
something that will Save/Load a DataSet to/from XML, and save a DataSet
to comma/tab-delimited, Excel, etc. that would be great. It doesn't
even all have to be the same tool.
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com


Jun 26 '06 #2

David,

Using the "DataSet" model is a good design, especially with your "it takes a
while to fill it" issue.

Using the basic ReadXml() and WriteXml() are good ways to store the data.

Basically, I do it like this:

I write a wrapper method like this:

public DataSet GetGoodEnoughDataSet ( bool forceRefresh )
{

}

The logic inside the method goes like this:

Check to see if the file exists , where you're written the out the xml for
the DataSet
(exists==true)If it exists, read the xml, and return that object.
(exists==false)If it doesn't exist, get a fresh copy from the database, and
write the file's xml to the filename, and return the DataSet

If I pass in the "forceRefresh" as true, then do the (exists==false) logic.

Now, that's a good way to have a "file cached" version of the DataSet.

If you want an "In Memory" cache for a winforms.. then you can try this
post:
http://groups.google.com/group/micro...a125e3bb2f4eb3

that post is a winforms equivalent of my blog posting: (below url)
http://sholliday.spaces.msn.com/PersonalSpace.aspx 10/24/2005 entry
The biggest issue you'll have is to figure out an intelligent (non hard
coded way ) to keep the file location.
C:\program files\myapplication\denormfiles\mydataset.xml
Make sure you do this part smartly, or you'll regret it.
You should also look at Strong Typed DataSets. These are just like DataSets
(they extend them), but you get better intellisense with them, and you
actually create tables in the DataSet you can refer to by name.
Here is the "behind the scenes" look at the strong typed dataset
If you go to your project and do a Add / New Item/ DataSet
give it the name TitlesDS
and then look at the "behind the scenes" xml, you can paste (to complete
replace the existing) lines with these.

Now, you have an "object" called TitlesDS in your project that you can work
with. And you still get the WriteXml() and ReadXml() methods.
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="TitlesDS" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:codegen="urn:schemas-microsoft-com:xml-msprop">
<xs:element name="TitlesDS" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Titles">
<xs:complexType>
<xs:sequence>
<xs:element name="title_id" type="xs:string" minOccurs="0" />
<xs:element name="title" type="xs:string" minOccurs="0" />
<xs:element name="type" type="xs:string" minOccurs="0"
nillable="true" />
<xs:element name="pub_id" type="xs:string" minOccurs="0"
nillable="true" />
<xs:element name="pub_name" type="xs:string" minOccurs="0"
nillable="true" />
<xs:element name="price" type="xs:double" minOccurs="0"
nillable="true" codegen:nullValue="0" />
<xs:element name="advance" type="xs:double" minOccurs="0"
nillable="true" codegen:nullValue="0" />
<xs:element name="royalty" type="xs:string" minOccurs="0"
nillable="true" codegen:nullValue="0" />
<xs:element name="ytd_sales" type="xs:string" minOccurs="0"
nillable="true" codegen:nullValue="0" />
<xs:element name="notes" type="xs:string" minOccurs="0"
nillable="true" codegen:nullValue="" />
<xs:element name="pubdate" type="xs:dateTime" minOccurs="0"
nillable="true" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Publishers">
<xs:complexType>
<xs:sequence>
<xs:element name="pub_id" type="xs:string" minOccurs="0" />
<xs:element name="pub_name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="titlesDSKey1">
<xs:selector xpath=".//Titles" />
<xs:field xpath="title_id" />
</xs:key>
</xs:element>
</xs:schema>

"David P. Donahue" <dd******@ccs.neu.edu> wrote in message
news:e0**************@TK2MSFTNGP05.phx.gbl...
I'm re-writing an application in C# that was originally written in
Delphi 7. The heart of the application is a DataSet displayed in a
DataGrid.

One of the main functions of the previous application was to save the
data to a file (it was XML, but the format is unimportant) that can be
re-loaded into the DataSet at a later time. (The reason for this was
that the queries which populate the DataSet can take a while to run, and
people wanted a way to just quickly load some "close enough to
up-to-date" data to do some quick work.)

Also, the DataSet (which consists of only one DataTable) could be
exported to a few other formats, such as comma-delimited or tab-delimited.

Can anyone recommend a good way of doing this? I Google around on the
subject, and find lots of articles explaining why exporting to XML is
good, but little explanation on ways of doing it. I did find something
that looked promising at
http://codebetter.com/blogs/brendan..../27/12229.aspx
but it seems to rely heavily on being a web application and I guess I'm
just not familiar enough to convert it to WinForms.

Does anyone have any recommendations for this? If I could just find
something that will Save/Load a DataSet to/from XML, and save a DataSet
to comma/tab-delimited, Excel, etc. that would be great. It doesn't
even all have to be the same tool.
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com

Jun 26 '06 #3
better yet, squeeze some efficiency by using a datatable, it can transition
thru appdomains in .net 2.0

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"sloan" <sl***@ipass.net> wrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...

David,

Using the "DataSet" model is a good design, especially with your "it takes
a
while to fill it" issue.

Using the basic ReadXml() and WriteXml() are good ways to store the data.

Basically, I do it like this:

I write a wrapper method like this:

public DataSet GetGoodEnoughDataSet ( bool forceRefresh )
{

}

The logic inside the method goes like this:

Check to see if the file exists , where you're written the out the xml for
the DataSet
(exists==true)If it exists, read the xml, and return that object.
(exists==false)If it doesn't exist, get a fresh copy from the database,
and
write the file's xml to the filename, and return the DataSet

If I pass in the "forceRefresh" as true, then do the (exists==false)
logic.

Now, that's a good way to have a "file cached" version of the DataSet.

If you want an "In Memory" cache for a winforms.. then you can try this
post:
http://groups.google.com/group/micro...a125e3bb2f4eb3

that post is a winforms equivalent of my blog posting: (below url)
http://sholliday.spaces.msn.com/PersonalSpace.aspx 10/24/2005 entry
The biggest issue you'll have is to figure out an intelligent (non hard
coded way ) to keep the file location.
C:\program files\myapplication\denormfiles\mydataset.xml
Make sure you do this part smartly, or you'll regret it.
You should also look at Strong Typed DataSets. These are just like
DataSets
(they extend them), but you get better intellisense with them, and you
actually create tables in the DataSet you can refer to by name.
Here is the "behind the scenes" look at the strong typed dataset
If you go to your project and do a Add / New Item/ DataSet
give it the name TitlesDS
and then look at the "behind the scenes" xml, you can paste (to complete
replace the existing) lines with these.

Now, you have an "object" called TitlesDS in your project that you can
work
with. And you still get the WriteXml() and ReadXml() methods.
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="TitlesDS" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:codegen="urn:schemas-microsoft-com:xml-msprop">
<xs:element name="TitlesDS" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Titles">
<xs:complexType>
<xs:sequence>
<xs:element name="title_id" type="xs:string" minOccurs="0" />
<xs:element name="title" type="xs:string" minOccurs="0" />
<xs:element name="type" type="xs:string" minOccurs="0"
nillable="true" />
<xs:element name="pub_id" type="xs:string" minOccurs="0"
nillable="true" />
<xs:element name="pub_name" type="xs:string" minOccurs="0"
nillable="true" />
<xs:element name="price" type="xs:double" minOccurs="0"
nillable="true" codegen:nullValue="0" />
<xs:element name="advance" type="xs:double" minOccurs="0"
nillable="true" codegen:nullValue="0" />
<xs:element name="royalty" type="xs:string" minOccurs="0"
nillable="true" codegen:nullValue="0" />
<xs:element name="ytd_sales" type="xs:string" minOccurs="0"
nillable="true" codegen:nullValue="0" />
<xs:element name="notes" type="xs:string" minOccurs="0"
nillable="true" codegen:nullValue="" />
<xs:element name="pubdate" type="xs:dateTime" minOccurs="0"
nillable="true" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Publishers">
<xs:complexType>
<xs:sequence>
<xs:element name="pub_id" type="xs:string" minOccurs="0" />
<xs:element name="pub_name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="titlesDSKey1">
<xs:selector xpath=".//Titles" />
<xs:field xpath="title_id" />
</xs:key>
</xs:element>
</xs:schema>

"David P. Donahue" <dd******@ccs.neu.edu> wrote in message
news:e0**************@TK2MSFTNGP05.phx.gbl...
I'm re-writing an application in C# that was originally written in
Delphi 7. The heart of the application is a DataSet displayed in a
DataGrid.

One of the main functions of the previous application was to save the
data to a file (it was XML, but the format is unimportant) that can be
re-loaded into the DataSet at a later time. (The reason for this was
that the queries which populate the DataSet can take a while to run, and
people wanted a way to just quickly load some "close enough to
up-to-date" data to do some quick work.)

Also, the DataSet (which consists of only one DataTable) could be
exported to a few other formats, such as comma-delimited or
tab-delimited.

Can anyone recommend a good way of doing this? I Google around on the
subject, and find lots of articles explaining why exporting to XML is
good, but little explanation on ways of doing it. I did find something
that looked promising at
http://codebetter.com/blogs/brendan..../27/12229.aspx
but it seems to rely heavily on being a web application and I guess I'm
just not familiar enough to convert it to WinForms.

Does anyone have any recommendations for this? If I could just find
something that will Save/Load a DataSet to/from XML, and save a DataSet
to comma/tab-delimited, Excel, etc. that would be great. It doesn't
even all have to be the same tool.
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com


Jun 28 '06 #4

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

Similar topics

3
by: Chris | last post by:
Could someone please provide me an effective means of exporting data from a data set (or data grid) to Excel?
6
by: Lester Moreno | last post by:
Hello all, Up to now C# have been an great experience but I found myself in a end of the road problem. Let say that you have two windows program running on a local network area. User1 and...
4
by: Oscar Thornell | last post by:
Hi, I have a relativley large/complex typed dataset that contains 7-8 tables and some supporting relational tables (lookups) for many-to-many relations. A good exampel would be a dataset that...
2
by: Mike P | last post by:
How do you go about exporting data in excel to a C# dataset? Any help would be really appreciated. Cheers, Mike
2
by: Tor Inge Rislaa | last post by:
I have a need for exporting the content of a table in a DataSet to an Excel Sheet. Is this possible? MyDataAdapter.Fill(MyDataSet) 'Something here to export MyDataSet.MyTable to Excel TIRislaa
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
4
by: BizWorld | last post by:
I am getting this error in exporting a crystal report (having two subreports) using C# code. i got the following exception at Export statement. Exception Details:...
0
by: Mike Collins | last post by:
I am trying to export data from multiple tables in SQL Server to an XML file so I can then import it to another database. It seems to be working fine for exporting, but I am having trouble...
4
by: myemail.an | last post by:
Hi all, I use Access 2007 and have the following problems: when exporting banal select queries (either to Excel or to a csv file) I find that exporting often doesn't work and creates a file with...
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.