By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,138 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Content of Datagridview to Excel

P: n/a
Hi folks,

I'm trying to get the actual content of a datagridview into Excel. It
seems to me that the most easy way is to use the WriteXML property of
a dataset.

So that's what I'm trying, but I'm getting it wrong when trying to get
the grids datasource into the dataset.

Firstly, is using the DataSet.WriteXML an okay approach?

And anyhow, what I'm I doing wrong:

Dim ds As New DataSet
ds = Me.DataGridView1.DataSource

Dim fs As New System.IO.FileStream("d:\test.xml",
IO.FileMode.CreateNew)

ds.WriteXml(fs)

fs.Close()
fs.Dispose()
ds.Dispose(

The problem is that the original dataset that puts data to the grid
has been disposed at this current time...

Thanks in advance for any help.
Regards /Snedker
Apr 5 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Morten,

Is this an ASPNET application, otherwise is this impossible.
The problem is that the original dataset that puts data to the grid
has been disposed at this current time...

Cor
Apr 5 '06 #2

P: n/a
On Wed, 5 Apr 2006 17:22:34 +0200, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:

It is not, it's an VB app. Nice just to know if it is doable or not.
I've changed the code letting the dataset live. It was disposed to
keep memory overhead down. Thanks for your reply.

/Snedker
Is this an ASPNET application, otherwise is this impossible.
The problem is that the original dataset that puts data to the grid
has been disposed at this current time...

Cor


Apr 6 '06 #3

P: n/a
Morten,

A datagridview is only a view on an bindable collection as a datatable.

Therefore it needs a reference. As long as that reference exist the
datasource cannot be disposed. Just the way as the Garbage Collector is
working. And if not, it is not anymore referenced by (in view of) the
DataGridView.

I hope this helps,

Cor
Apr 6 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.