How to fill a dataDable with the value of a textBox?

1

I want to pass the value of a textbox to a dataTable

valor.Text = dataTable...

I do not use Database.

    
asked by Luis Fernando 11.05.2018 в 19:38
source

1 answer

3
//Se crea el dataTable
DataTable dt = new DataTable();

//Creamos una columna para el datatable
DataColumn dc = new DataColumn("Columna1", typeof(String));

//agregamos la columna creada al dataTable
dt.Columns.Add(dc);

//ahora creamos una fila para el DataTable
DataRow dr = dt.NewRow();

//Aqui es donde asignamos el valor del textBox al valor del row a agregar al DT
dr[0] = textBox.Text;

//agregamos la fila al final del dataTable
dt.Rows.Add(dr);


// o lo insertas en cierta posicion
int yourPosition = 0;
dt.Rows.InsertAt(dr, yourPosition);
    
answered by 11.05.2018 / 19:48
source