472,783 Members | 934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 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 1995
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.