Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have some data in a data grid.I want to save them in a part of my system or in a disk.I use save file dialog ,but i don`t know which codes should i use for it!
Please help me?
Best regards
Posted
Updated 31-May-11 1:28am
v4
Comments
Kim Togo 29-May-11 7:41am    
Is your data in data grid from a DataSet/DataTable ?
k5_ce 29-May-11 7:50am    
I use data reader to load my data from my data base
Kim Togo 29-May-11 8:44am    
The idea is, if it was a DataSet/DataTable you can do as John suggested. You can save data to a XML file and when needed you can read the XML back into a DataSet/DataTable and then have it showed again in DataGrid.

Use the DataSet.WriteXML() method.
 
Share this answer
 
Comments
Wonde Tadesse 29-May-11 15:16pm    
5+
Here is what you can do
C#
DataTable dataTable = new DataTable();
dataTable.Load(reader);// replace reader with your data reader instance.
dataTable.WriteXml("fileName");
 
Share this answer
 
Comments
parmar_punit 30-May-11 3:05am    
good one, my 5
Wonde Tadesse 30-May-11 9:57am    
Thanks.
Thanks,but my problem hasn`t solved until now.
what should i write instead of filename?the path that i want to save the data of this data grid in?or some thing else?
That is what i do:

DataTable dt = new DataTable();
dt.Load(dr1);
dt.WriteXml("E:");

it doesn`t work ,it doesn`t have any error but after i run the project,it says access to the path 'E:\ is denied.
if i write dt.WriteXml("E:\aname"),it says illegal characters in path after running.
I don`t know what to do,please help me,it is really important for me.
Thanks a lot
 
Share this answer
 
v2
Thanks a lot,but as i said i use data reader for loading data from data base,not data set or data table.what can i do in this way?
 
Share this answer
 
export it to EXCEL or PDF
use the folling code in a certain event such as a btn to export grid view
just copy and paste (change the gridview name)

GridView1.ExportSettings.IgnorePaging = true;
GridView1.ExportSettings.OpenInNewWindow = true;
GridView1.MasterTableView.ExportToExcel();
 
Share this answer
 
v2
it better to store the grid data into either excel file, pdf and word file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900