Esempio n. 1
0
 public IDataReader GetData(int i)
 {
     if (SDR != null)
     {
         return(SDR.GetData(i));
     }
     else
     {
         return(ODR.GetData(i));
     }
 }
 public static void VisualizzaConsoleListaVeicoli()
 {
     ///Lista visualizzata in Console
     if (connstr != null)
     {
         try
         {
             OleDbConnection connection = new OleDbConnection(connstr);
             using (connection)
             {
                 connection.Open();
                 OleDbCommand cmd = new OleDbCommand();
                 cmd.Connection = connection;
                 ///Comandi di eseguzione SQL
                 cmd.CommandText = "SELECT * FROM Veicoli";
                 OleDbDataReader reader = cmd.ExecuteReader();
                 if (reader.HasRows) //Significa che nella tabella ci sono dei dati
                 {
                     Console.WriteLine("LISTA VEICOLI");
                     Console.WriteLine("ID | MARCA | MODELLO | COLORE | CILINDRATA | POTENZAKW | IMMATRICOLAZIONE | USATO | KMZERO | KM_PERCORSI | NUMAIRBAG | MARCASELLA | PREZZO");
                     while (reader.Read())
                     {
                         Console.WriteLine("{0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} | {8} | {9} | {10} | {11} | {12}",
                                           reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetInt32(4), reader.GetDouble(5),
                                           reader.GetData(6), reader.GetBoolean(7), reader.GetBoolean(8), reader.GetInt32(9), reader.GetInt32(10), reader.GetString(11), reader.GetInt32(12));
                     }
                 }
                 else
                 {
                     Console.WriteLine("Veicoli Inesistenti");
                 }
                 reader.Close();
             }
         }
         catch (OleDbException exc)
         {
             throw new Exception("Connessione interrott " + exc);
         }
     }
 }