views:

127

answers:

1

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

+2  A: 

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++)
        {
            row[col] = set.GetValue(col);
        }
        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.

MusiGenesis