Rows not showing up in DataTable c#
<p>I am trying to copy data from my datagridview to a datatable so i can export to a csv file</p>

<p>here is the code</p>

<pre><code>public DataTable createdatatablefromdgv()
   {
       DataTable dsptable = new DataTable();

       for (int i = 0; i &lt; dataGridView1.Columns.Count; i++)
       {
           DataColumn dspcolumn = new DataColumn(dataGridView1.Columns[i].HeaderText);
           dsptable.Columns.Add(dspcolumn);
       }
       int noOfColumns = dataGridView1.Columns.Count;
       foreach (DataGridViewRow dgvr in dataGridView1.Rows)
       {
           DataRow dataRow = dsptable.NewRow();

           for (int i = 0; i &lt; noOfColumns; i++)
           {
               dataRow[i] = dgvr.Cells[i].Value.ToString();
           }

       }
       return dsptable;
   }
</code></pre>

<p>It seems like it copies the data from the the grid to to the table but when I return the datatable all there is the columns no rows</p>
