title: Convert type of a columns in datatable
body: <p>I import a csv file into a datatable which, unfortunately, put my datas into string columns even those with figures.</p>
  
  <p>So I have to convert the format of some columns (unless there is an other way) into datetime, integer or double why I wrote the following code :</p>
  
  <pre><code>Public Sub ChangeFieldType(ByRef dataTable As DataTable, ByVal fieldIndex As Integer, ByVal newType As Type)
      Dim newDataTable As DataTable = dataTable.Clone
  
      newDataTable.Columns(fieldIndex).DataType = newType
      For Each row As DataRow In dataTable.Rows
          newDataTable.ImportRow(row)
      Next
      dataTable = newDataTable
  End Sub
  </code></pre>
  
  <p>But there are some empty cells which in string format is vbnullstring. My question is is there an easier way then my code and if not is there an faster way than converting the empty cells then that way :</p>
  
  <pre><code>Public Sub ChangeFieldType(ByRef dataTable As DataTable, ByVal fieldIndex As Integer, ByVal newType As Type)
      Dim newDataTable As DataTable = dataTable.Clone
  
      newDataTable.Columns(fieldIndex).DataType = newType
      For Each row As DataRow In dataTable.Rows
          If row(fieldIndex) = vbNullString Then
              row(fieldIndex) = Nothing
          End If
          newDataTable.ImportRow(row)
      Next
      dataTable = newDataTable
  End Sub
  </code></pre>
  
  <p>Because this is very very slow.</p>
  
  <p>Thanks</p>