Return int

Jun 28, 2011 at 8:50 AM
Hi, I am using OPF 3 with several persistant Types, but I also need to get just a List of Numbers from my Database - is this possible without registering another persistant Type? The Statement IList<int> userIds = context.GetObjectSet<int>(new SqlQuery(query, userId)); obviously didn't work. Greetings PuratorLE
Aug 4, 2011 at 5:06 AM
Edited Aug 4, 2011 at 5:13 AM

with one number i do.

        static object ExecuteScalar(this IQuery query)
        {
            IDbCommand cmd = context.SqlRaw.CreateCommand(query);
            object ret = cmd.ExecuteScalar();
            return ret;
        }

    static void Main()

   {

      IQuery query = new SqlQuery(query, userId);

    int myValue = (int)ExecuteScalar(query);

    DataTable listInt  = query.getDataTable(query)

  }

with all numbers i think you need return datatable.

static DataTable getDataTable(this IQuery query)
        {
            DataTable ret = new DataTable();
            try
            {
                IDbCommand cmd = context.SqlRaw.CreateCommand(query);
                IDataReader reader = cmd.ExecuteReader();
                ret.Load(reader);
            }
            catch
            {
            }
            return ret;
        }

 

good luck