• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1535
  • Last Modified:

Export Datagrid to CSV not Datagridview

Export DataGrid to CSV.  I am trying to find the solution to a datagrid instead of a datagridview.  
I am using vb .net 2003.  I saw the datagridview code but I need a conversion of that to fit a datagrid only.

Thanks.
0
mphillip85
Asked:
mphillip85
  • 2
  • 2
1 Solution
 
surajgupthaCommented:
Have thought about iterating throw all the cells in the datagrid and generating a CSV manually?
0
 
mphillip85Author Commented:
I am trying to have a function that I can just pass the datagrid name to and it does the rest.  I basically know how to iterate through the rows and cells, but I cannot figure out how to find the column names and/or how many columns and/or how many rows.  I can get the row count from the dataset that I gave as the datasource to the datagrid.  

I just want to pass a few parameters and generate a CSV.  I am having to do many datagrid reports, that I am trying to make a function call to achieve this.
0
 
surajgupthaCommented:
ok yeah thats a good idea. why not iterate through the dataset you are going to bind to the datagrid and generate the csv??

List<String> csvs = new List<String>();
for(int i=0; i < datatable.Rows.Count ; i++)
{
String rowcsv = "";
for(int columCounter = 0; columnCounter < dataTable.Rows[i].Cells.Count; columnCounter++)
{
rowcsv+= dataTable.Rows[i].Cells[columnCounter].ToString() + "'";
}
csvs.Add(rowcsv)
}

THis is the pseudo code of the function that takes a DataTable as input and returns a CSV array. Improvise on this with your requirements
0
 
mphillip85Author Commented:
I would use the dataset except that I do not use all the columns in the dataset to display.  Or else I would have 10 times the datasets I needed to do everything.  I need to just export only what is displayed in the datagrid.  Or else I would have used the dataset and made calls to find the columns and etc.

0
 
Qaiser_Mehmood_MughalCommented:
Here is the complete solution of your problem.

http://www.netomatix.com/GridExportToCSV.aspx

find and test.
If its helpfull accept the solution.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now