How to know if my DataTable, DataSet or DataView contains empty fields and remove them from the table,

0

I am trying to get the name of the columns of each table of a base in Access and store them in a DataTable inside a DataSet.

The name of the columns is the name of each Access table and each column name of each table.

The issue here is that when I print the information in the datagridview I get spaces.

There will be a way to avoid or eliminate the blank spaces within the datagridview or the datatable.

I thank you in advance for your time and attention in seeing my article.

I leave a part of the code so you can see more or less what this is about.

DataTable dataTablealldata = new DataTable("Tabla_ColumnasDB");
DataSet resultado = new DataSet();

//En esta lista se utiliza para almacenar cada valor de cada fila de una columna.
List<string> LG_Dato = new List<string>();

//En esta lista se utiliza para almacenar el nombre de las tablas de la base de datos "Access".
List<string> lgtablas = new List<string>();

//Aqui almaceno la tabla en el dataset resultado.Tables.Add(dataTablealldata);

//Aqui uso un metodo que captura las tablas que contenga la base de datos en una lista generica
lgtablas = this.CapturarEsquemaTablasAccess(
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Documents\BD_Migracion.mdb"
);

//Captura la informacion de cada tabla de la base de datos en Access y la almacena en el dataset.
for (int i = 0; i < lgtablas.Count; i++)
{   
    //Aqui uso un metodo que lee y almacena la consulta hasta "N" tablas que haya.
    this.leer_datos_db("Select * FROM "+lgtablas[i], ref resultado, lgtablas[i]);

}

//Crea la columna de la tabla "dataTablealldata" con el nombre de la tabla correspondiente de la lista generica
for (int g = 0; g < lgtablas.Count; g++)
{
    LG_Dato.Clear();
    dataTablealldata.Columns.Add(
        lgtablas[g], 
        Type.GetType("System.String")
    );

    LG_Dato = ObtenerNombresColumnasTabla(
        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Documents\BD_Migracion.mdb", 
        lgtablas[g]
    );

    //Guarda el nombre de cada columna de la tabla "lgtablas['x']" en el DataTable en la Fila correspondiente.
    for (int X = 0; X < LG_Dato.Count; X++)
    {

        DataRow Row1;                   
        Row1 = dataTablealldata.NewRow();

        Row1[lgtablas[g]] = LG_Dato[X];
        dataTablealldata.Rows.Add(Row1);                                     
    }
}

//Imprime la informacion.
this.DGV_Consulta.DataSource = mifiltro;
    
asked by Carlos Ivan CM 17.12.2018 в 07:27
source

0 answers