Convert DataSet To Excel

G

Guest

I am running the following code to retrieve a DataSet:

public DataView CreateGroupSource()
{
string groupConnect = Session["connect"].ToString();
string groupSelect = "Select grpname from Maxusergroups where usrname = "
+ "'" + userText.Text + "'";
oda = new OleDbDataAdapter(groupSelect, groupConnect);
DataSet ds = new DataSet();
oda.Fill(ds, "group");
DataView group = ds.Tables["group"].DefaultView;
return group;
}

When I click on a button on a web form I want to convert the information
toan excel spreadsheet.

How do I accomplish this task?

Thanks,

Dave
 
N

Nicholas Paldino [.NET/C# MVP]

Dave,

You would create a dataadapter, and then you would set the
InsertCommand, DeleteCommand and UpdateCommand to the commands that will
perform those operations. Then, feed the dataset to the Update method on
the DataAdapter, and it should work.

Hope this helps.
 
N

Nicholas Paldino [.NET/C# MVP]

Chad,

Since Excel can read XML, and the XML produced by the DataSet is valid,
it can read them. However, you have to handle all the mappings yourself.

One catch though, you have to be using Excel XP, or 2003 and up (I'm not
sure which version support was added).

If that is not a problem for you, then I would use that.
 
F

Fredrik Wahlgren

Nicholas Paldino said:
Chad,

Since Excel can read XML, and the XML produced by the DataSet is valid,
it can read them. However, you have to handle all the mappings yourself.

One catch though, you have to be using Excel XP, or 2003 and up (I'm not
sure which version support was added).

If that is not a problem for you, then I would use that.

Another option is to use automation from within your C# application. Start a
new instance of Excel, make it visible, loop thru your values and pass them
one by one. You should be able to find several examples of this on the
Internet.

/Fredrik
 
C

Chad Z. Hower aka Kudzu

Nicholas Paldino said:
Since Excel can read XML, and the XML produced by the DataSet is
it can read them. However, you have to handle all the mappings
yourself.

Thats what I thought. Unless he wants to go through ODBC or Automation, the
simplest solution might be best. A CSV. :)


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top