Associative Array / Hash / Hashtable Using Connector / NET

Hi guys, working with asp.NET and C #, I use the connect / NET plugin to connect to MySQL db (no surprises!).

And it works great, can connect, run queries, etc. etc. everything is fine and dandy, but is it possible to return a Hashtable or similar results? Save the execution of the description in the same table to get the column names and use these values ​​to create a Hash every time.

Thanks,

Psi

+3
source share
2 answers

MySQL C/++, , , # ( #), , . , . API ( ) mysql_fetch_field_direct() - . . API ( + /) -.

, , , , mysql_fetch_field_direct() . , /. , , - ..

, , , , , .

+2

in.net , datatable datarows, hashtables, , -,

public static Hashtable convertDataRowToHashTable(DataRow dr)
{
    if (dr == null)
    {
        return null;
    }

    Hashtable ret = new Hashtable(dr.Table.Columns.Count);

    for (int iColNr = 0; iColNr < dr.Table.Columns.Count; iColNr++)
    {
        ret[dr.Table.Columns[iColNr].ColumnName] = dr[iColNr];
    }
    return ret;
}

(hast table to datrow) , datarow ( ), newRow = myDataTable.NewRow(); , , hashtable

newRow["column1"]="some value";

-, datatable, myTable.Columns.Add( "", "" );

,

+1

Source: https://habr.com/ru/post/1718016/


All Articles