[c#] Database

Custom Title Activated
Loyal Member
Joined
May 18, 2006
Messages
2,064
Reaction score
14
The problem is that all rows in the dictionary is the same as the first row. I might've overlooked the code, but do you find any mistakes in the following code that caused the undesirable result?

I'm using Mono.SQLite for your information.

Thanks in advance.

Code:
        /// <summary>
        /// Executes a SQL query
        /// </summary>
        /// <param name="query">The query to execute</param>
        /// <returns></returns>
        public Dictionary<int, List<object>> ExecuteQuery(string query)
        {
            Dictionary<int, List<object>> rows = new Dictionary<int, List<object>>();
            IDbCommand command = Connection.CreateCommand();
            command.CommandText = query;
            IDataReader reader = command.ExecuteReader();
            int c = 0;
            List<object> columns = new List<object>();
            while (reader.Read())
            {
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    columns.Add(reader.GetValue(i));
                }
                rows.Add(c, columns);
                c++;
            }
            reader.Dispose();
            command.Dispose();
            return rows;
        }
 
Back