예제 #1
0
        public virtual IList<object> GetList(SqlListGenerator generator)
        {
            HashSet<object> set = new HashSet<object>();
            using (var conn = CreateConnection())
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandTimeout = CommandTimeout;
                    generator.UpdateCommand(cmd);
                    using (var reader = cmd.ExecuteReader())
                    {
                        int idx = -1;
                        try { idx = reader.GetOrdinal("ID"); }
                        catch { }

                        while (reader.Read())
                        {
                            // assumes either 1 or 2 columns. If 2, one will be ID column
                            var item = reader.GetValue(idx != -1 ? 1 - idx : 0);
                            if (!set.Contains(item))
                                set.Add(item);
                        }
                    }
                }
            }
            return new List<object>(set);
        }
예제 #2
0
        private int Execute(SqlListGenerator generator)
        {
            using (var cmd = _conn.CreateCommand())
            {
                generator.UpdateCommand(cmd);

                System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter((System.Data.SqlClient.SqlCommand)cmd); //we are now tieing ourselves to SQL
                System.Data.DataTable tbl = new System.Data.DataTable();
                adapter.Fill(tbl);

                return tbl.Rows.Count;
            }
        }