Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert SQLCEResultSet resultview to datatable

Is it possible to convert a sqlceresultset.resultview to datatable?

like image 441
Jepe d Hepe Avatar asked Nov 24 '25 12:11

Jepe d Hepe


1 Answers

Not tested, but this should do what you need:

public DataTable ResultSetToDataTable(SqlCeResultSet set)
{
    DataTable dt = new DataTable();

    // copy columns
    for (int col = 0; col < set.FieldCount; col++)
    {
        dt.Columns.Add(set.GetName(col), set.GetFieldType(col));
    }

    // copy data
    while (set.Read())
    {
        DataRow row = dt.NewRow();
        for (int col = 0; col < set.FieldCount; col++)
        {
            int ordinal = set.GetOrdinal(GetName(col));
            row[col] = set.GetValue(ordinal);
        }
        dt.Rows.Add(row);
    }

    return dt;
}

There's no built-in way to do this (that I know of), probably because a SqlCeResultSet does not store actual data like a DataTable does.

like image 92
MusiGenesis Avatar answered Nov 26 '25 02:11

MusiGenesis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!