mugsey
asked on
loop through datareader and export to csv file, use file dialog to save on users desktop
I have a datareader as follows
while (thisReader.Read())
{
strvalues += (string)thisReader["FirstN ame"].ToSt ring() + ", " + (string)thisReader["LastNa me"].ToStr ing() + ", ";
strvalues += (string)thisReader["Addres s1"].ToStr ing() + ", " + (string)thisReader["PostCo de"].ToStr ing() + ", " + (string)thisReader["Countr y"].ToStri ng() + ", ";
if (strvalues.Length > 2)
strvalues = strvalues.Substring(0, strvalues.Length - 2) + "\n";
}
Now how can I amend the above code so it produces a valid CSV or EXCEL file. Also I need a dialog box that the user can select to save the file to the desk top
while (thisReader.Read())
{
strvalues += (string)thisReader["FirstN
strvalues += (string)thisReader["Addres
if (strvalues.Length > 2)
strvalues = strvalues.Substring(0, strvalues.Length - 2) + "\n";
}
Now how can I amend the above code so it produces a valid CSV or EXCEL file. Also I need a dialog box that the user can select to save the file to the desk top
hope this helps....http://www.codeproject.com/useritems/Export_large_data_to_xl.asp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK gang, thanks I will have a go tomorrow when I am back in work. Thanks for your comments
ASKER
Actually I have a datareader not a gridview, can I do this with a datareader?
Yes, at the very top are 2 lines of code that load your reader into a DataTable:
DataTable table = new DataTable();
table.Load(thisReader);
'Etc...
DataTable table = new DataTable();
table.Load(thisReader);
'Etc...
ASKER
VBRocks you know your stuff!!!!!!!!!!!!!!!!!!!!! !
Will update tomorrow if that is OK, however you will certainly get points. Thanks again for your great comments
Will update tomorrow if that is OK, however you will certainly get points. Thanks again for your great comments
ASKER
Thanks but how can I do this
SaveFileDialog diag = new SaveFileDialog();
in ASP.NET
Is this not for windows forms?
SaveFileDialog diag = new SaveFileDialog();
in ASP.NET
Is this not for windows forms?
You're right mugsey... That is a windows form control. And I"m not sure how to do that with ASP.NET.
My apologies. :(
My apologies. :(
ASKER
No problem, I will award you the points for you contributions!
Can anyone append info on how to include the Headers in the CSV export?