Hello that good night, I have the following code that creates a table with 4 columns and the number of rows is provided by the user, this table is exported to a DataGridView but if I generate more than one million records it takes a little bit. Then I would like to know if the DataTable can be exported directly to CSV. The code I use is the following:
Sub BtnCrearClick(sender As Object, e As EventArgs)
Dim IDColumna As New DataColumn(txtID.Text)
IDColumna.DataType=GetType(Integer)
IDColumna.AutoIncrement=True
Dim Nombre As New DataColumn(txtNombre.Text)
Nombre.DataType=GetType(String)
Dim App As New DataColumn(txtApp.Text)
App.DataType=GetType(String)
Dim Apm As New DataColumn(txtApm.Text)
Apm.DataType=GetType(String)
Dim TablaNombres As New DataTable(txtTabla.Text)
TablaNombres.Columns.Add(IDColumna)
TablaNombres.Columns.Add(Nombre)
TablaNombres.Columns.Add(App)
TablaNombres.Columns.Add(Apm)
TablaNombres.Constraints.Add("Key1", IDColumna, True)
Dim nombres As String()={"Aaron","Abel","Abelardo","Abraham","Adalberto","Adolfo","Adrian","Agustin","Alan","Alejandro",
"Benjamin","Bernardo","Baldomero","Baltasar","Barack"}
Dim apellidos As String()={"Pineda", "Bernal", "Espinoza", "Spindola", "Brisuela", "Gutierrez", "Escarcega", "Muñiz", "Lopez", "Martinez", "Piña",
"Vega", "Ortiz", "Barcenas", "Lopez", "Martinez"}
Dim aleatorio As New Random
Dim row As DataRow
Dim i As Integer
For i=0 To Convert.ToInt32(txtFilas.Text)
row=TablaNombres.NewRow()
row(txtID.Text)=i
row(txtNombre.Text)=nombres(aleatorio.Next(0,nombres.Length))
row(txtApp.Text)=apellidos(aleatorio.Next(0,nombres.Length))
row(txtApm.Text)=apellidos(aleatorio.Next(0,nombres.Length))
TablaNombres.Rows.Add(row)
Next
tabla1.DataSource=TablaNombres
End Sub
'