How to add field column name to dataset in C#



How do I add column name to a dataset in C#? I have been searching everywhere and couldn’t figure out a way to add names to my columns. Please, can someone help me. Thank you in advance.



Hi locquan,

The dataset needs to be a compound for its columns (i.e. members) to have names associated to these. Not sure how this is done with other libraries but with HDFql the creation of, e.g., a compound dataset named dset of one dimension (size 100) composed of two columns (named first_column and second_column) both of data type float can be done as follows in C#:

HDFql.Execute("CREATE DATASET dset AS COMPOUND(first_column AS FLOAT, second_column AS FLOAT)(100)");

In case of need, to get the name of the columns (i.e. members) of dataset dset just do the following:

HDFql.Execute("SHOW MEMBER dset");

Alternatively, the dataset could be just a regular 2D dataset (like the one illustrated in your screenshot) with one attribute containing the name of the columns. Example:

// create a dataset named 'dset' of two dimensions (size 100x2) of data type float
HDFql.Execute("CREATE DATASET dset AS FLOAT(100, 2)");

// create an attribute named 'names' (associated to dataset 'dset') of one dimension (size 2) of data type varchar with initial values 'first_column' and 'second_column'
HDFql.Execute("CREATE ATTRIBUTE dset/names AS VARCHAR(2) VALUES(first_column, second_column)");

As a side note, besides C#, the HDFql snippets above can be executed in C, C++, Java, Python, Fortran and R without any modifications - ideal if you/your organization work with several of these programming languages at the time.

Hope this helps!