示例#1
0
 public DlgSupcomStats()
 {
     DataRow current;
     this.components = null;
     this.mConnection = new OdbcConnection("DSN=gpgstats;");
     this.InitializeComponent();
     this.mConnection.Open();
     OdbcDataReader reader = new OdbcCommand("SELECT * FROM units_player", this.mConnection).ExecuteReader();
     DataTable table = new DataTable();
     using (IEnumerator<object> enumerator = (IEnumerator<object>)reader.GetSchemaTable().Rows.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             current = (DataRow) enumerator.Current;
             table.Columns.Add(current[0].ToString(), (System.Type) current[5]);
         }
     }
     while (reader.Read())
     {
         current = table.NewRow();
         for (int i = 0; i < reader.FieldCount; i++)
         {
             current[i] = reader[i];
         }
         table.Rows.Add(current);
     }
     reader.Close();
     this.mConnection.Close();
     this.pivotGridControl1.DataSource = table;
 }
示例#2
0
        /// <summary>
        /// Performs a SQL query and returns the selected in the first found row as a String array. Usable for only one row.
        /// </summary>
        /// <param name="Query">The SQL query that selectes a row and the fields to get. LIMIT 1 is added.</param>
        public static string[] runReadRowStrings(string Query)
        {
            try
            {
                ArrayList rowBuilder = new ArrayList();
                OdbcDataReader rowReader = new OdbcCommand(Query + " LIMIT 1", dbConnection).ExecuteReader();

                while (rowReader.Read())
                {
                    for (int i = 0; i < rowReader.FieldCount; i++)
                    {
                        try { rowBuilder.Add(rowReader[i].ToString()); }
                        catch { rowBuilder.Add(""); }
                    }
                }
                rowReader.Close();
                return (string[])rowBuilder.ToArray(typeof(string));
            }
            catch (Exception ex)
            {
                Logging.logError(ex.Message + ", query = " + Query);
                return new string[0];
            }
        }
示例#3
0
        /// <summary>
        /// Performs a SQL query and returns all vertical matching fields as a string array. Only the first supplied column is looked for.
        /// </summary>
        /// <param name="Query">The SQL query that selects a column.</param>
        /// <param name="maxResults">Adds as LIMIT to the query. Using this, the array will never return more than xx fields in of the column. When maxResults is supplied as 0, then there is no max limit.</param>
        public static string[] runReadColumnStrings(string Query, int maxResults)
        {
            if (maxResults > 0)
                Query += " LIMIT " + maxResults;

            try
            {
                ArrayList columnBuilder = new ArrayList();
                OdbcDataReader columnReader = new OdbcCommand(Query, dbConnection).ExecuteReader();

                while (columnReader.Read())
                {
                    try { columnBuilder.Add(columnReader[0].ToString()); }
                    catch { columnBuilder.Add(""); }
                }
                columnReader.Close();

                return (string[])columnBuilder.ToArray(typeof(string));
            }
            catch (Exception ex)
            {
                Logging.logError(ex.Message + ", query = " + Query);
                return new string[0];
            }
        }