Esempio n. 1
0
        public static T queryToObject <T>(string query, List <addWithValue> _vals) where T : new()
        {
            NpgsqlConnection connection = new NpgsqlConnection(RouteConfig.connectString);

            connection.Open();
            NpgsqlCommand command = new NpgsqlCommand(query, connection);

            for (int i = 0; i < _vals.Count; i++)
            {
                command.Parameters.AddWithValue(_vals[i].VAR, _vals[i].VAL);
            }
            NpgsqlDataReader  dataReader = command.ExecuteReader();
            NpgsqlDataAdapter da         = new NpgsqlDataAdapter();
            DataTable         dt         = new DataTable();

            for (int i = 0; dataReader.Read(); i++)
            {
            }
            dt.Load(dataReader);
            da.SelectCommand = command;
            da.Fill(dt);
            T obj = TableUtils.CreateObjectFromTable <T>(dt);

            connection.Close();
            return(obj);
        }
Esempio n. 2
0
        public static T queryToObject <T>(string query) where T : new()
        {
            NpgsqlConnection connection = new NpgsqlConnection(RouteConfig.connectString);

            connection.Open();
            NpgsqlCommand     command    = new NpgsqlCommand(query, connection);
            NpgsqlDataReader  dataReader = command.ExecuteReader();
            NpgsqlDataAdapter da         = new NpgsqlDataAdapter();
            DataTable         dt         = new DataTable();

            for (int i = 0; dataReader.Read(); i++)
            {
            }
            dt.Load(dataReader);
            da.SelectCommand = command;
            da.Fill(dt);
            T obj = TableUtils.CreateObjectFromTable <T>(dt);

            connection.Close();
            return(obj);
        }