473,756 Members | 4,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ne u.edu
http://www.cyber0ne.com
Jun 26 '06 #1
3 2052
das
As far as Exporting a DataSet to a XML file, simply use:

myDataSet.Write Xml(xmlWriter) //xmlWriter of type: StreamWriter

Vice versa for Reading XML document into a DataSet

myDataSet.ReadX ml(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.Table s[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.ne u.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 GetGoodEnoughDa taSet ( 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)I f 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 "forceRefre sh" 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\myapplica tion\denormfile s\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="u rn:schemas-microsoft-com:xml-msdata"
xmlns:codegen=" urn:schemas-microsoft-com:xml-msprop">
<xs:element name="TitlesDS" msdata:IsDataSe t="true">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<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:nullVal ue="0" />
<xs:element name="advance" type="xs:double " minOccurs="0"
nillable="true" codegen:nullVal ue="0" />
<xs:element name="royalty" type="xs:string " minOccurs="0"
nillable="true" codegen:nullVal ue="0" />
<xs:element name="ytd_sales " type="xs:string " minOccurs="0"
nillable="true" codegen:nullVal ue="0" />
<xs:element name="notes" type="xs:string " minOccurs="0"
nillable="true" codegen:nullVal ue="" />
<xs:element name="pubdate" type="xs:dateTi me" minOccurs="0"
nillable="true" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Publisher s">
<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="titlesDSK ey1">
<xs:selector xpath=".//Titles" />
<xs:field xpath="title_id " />
</xs:key>
</xs:element>
</xs:schema>

"David P. Donahue" <dd******@ccs.n eu.edu> wrote in message
news:e0******** ******@TK2MSFTN GP05.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.ne u.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.ne t> wrote in message
news:O$******** ******@TK2MSFTN GP02.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 GetGoodEnoughDa taSet ( 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)I f 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 "forceRefre sh" 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\myapplica tion\denormfile s\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="u rn:schemas-microsoft-com:xml-msdata"
xmlns:codegen=" urn:schemas-microsoft-com:xml-msprop">
<xs:element name="TitlesDS" msdata:IsDataSe t="true">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<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:nullVal ue="0" />
<xs:element name="advance" type="xs:double " minOccurs="0"
nillable="true" codegen:nullVal ue="0" />
<xs:element name="royalty" type="xs:string " minOccurs="0"
nillable="true" codegen:nullVal ue="0" />
<xs:element name="ytd_sales " type="xs:string " minOccurs="0"
nillable="true" codegen:nullVal ue="0" />
<xs:element name="notes" type="xs:string " minOccurs="0"
nillable="true" codegen:nullVal ue="" />
<xs:element name="pubdate" type="xs:dateTi me" minOccurs="0"
nillable="true" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Publisher s">
<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="titlesDSK ey1">
<xs:selector xpath=".//Titles" />
<xs:field xpath="title_id " />
</xs:key>
</xs:element>
</xs:schema>

"David P. Donahue" <dd******@ccs.n eu.edu> wrote in message
news:e0******** ******@TK2MSFTN GP05.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.ne u.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
8011
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
4638
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 user2 have the same information in the dataset and user1 makes a change, unless user2 refill all his tables in his dataset he can't see the
4
3810
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 contained the whole Northwind database with all tables and relations. In my business logic I will retrive a populated instance of the dataset and perform some operations (adding/deleting/updating of rows in various tables...).
2
1928
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
1093
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
2415
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 exporting ALL data from the datagrid control. Exporting data works fine when I show all data on the datagrid control. I'd like to shows only 30 records on the datagrid control instead of ALL data using page navigation, and perform exporting...
4
2068
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: CrystalDecisions.CrystalReports.Engine.ExportException: Error in File C:\WINDOWS\TEMP\temp_015d322b-ea06-426e-92d3-656ad11ef627.rpt: Error detected by export DLL: ..........................here is the report
0
1511
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 importing the file. Can someone show me where I am going wrong. Even though I say the export is working, I am including it below in case there is something in there that needs to be changed. Also, the code I am including is VERY rough right now and will...
4
2394
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 the WHOLE dataset, i.e. including those rows which the criteria of the query excluded. For example: let's say I have a database with sales by region. I create a select query to only show sales from Europe. The query runs
0
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8736
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.