Esempio n. 1
0
 public DatabaseResult runQuery(string query)
 {
     if (!isConnected)
         throw new Exception("Database is disconnected - unable to run query");
     MySqlCommand command = new MySqlCommand(query, this.sqlConn);
     DatabaseResult dbresult = new DatabaseResult();
     try
     {
         //command.ExecuteNonQuery();
         MySqlDataReader reader = command.ExecuteReader();
         for (int i = 0; i < reader.FieldCount; i++)
         {
             dbresult.addColumn(reader.GetName(i));
         }
         while (reader.Read() != false)
         {
             string[] values = new string[reader.FieldCount];
             for (int i = 0; i < reader.FieldCount; i++)
             {
                 if (reader.IsDBNull(i))
                     values[i] = null;
                 else
                     values[i] = reader.GetString(i);
             }
             dbresult.insertRow(values);
         }
         reader.Close();
     }
     catch (Exception excp)
     {
         Exception myExcp = new Exception("Could not verify user. Error: " +
             excp.Message, excp);
         throw (myExcp);
     }
     return dbresult;
 }