Código:
string myConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=OcupacionBA.mdb;";
List<String> resultados = new List<String>();
try
{
// Open OleDb Connection
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
// Execute Queries
OleDbCommand cmd = myConnection.CreateCommand();
cmd.CommandText = "select Estacion,Frecuencia,Min(Intensidad),Max(Intensidad),Count(Frecuencia) from frecB GROUP BY Estacion, Frecuencia";
OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); // close conn after complete
while (reader.Read())
{
resultados.Add(reader.GetString(0) + "," + reader.GetDecimal(1) + "," + reader.GetDecimal(2) + "," + reader.GetDecimal(3) + "," + reader.GetInt32(4));
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine("OLEDB Connection FAILED: " + ex.Message);
}
string[] R1 = resultados.ToArray();
MessageBox.Show("" + R1.Length);
try
{
// Open OleDb Connection
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
int a = 0;
for (int i = 0; i < R1.Length; ++i)
{
string[] datos = R1[i].Split(',');
string estacion = datos[0];
double umbral = Convert.ToDouble(datos[2]) + 5;
double frecuencia = Convert.ToDouble(datos[1]);
// Execute Queries
OleDbCommand cmd = myConnection.CreateCommand();
cmd.CommandText = "select count(Id) from frecB WHERE Intensidad >=" + umbral + " AND Frecuencia =" + frecuencia + " AND Estacion = \"" + estacion + "\"";
OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); // close conn after complete
int mm = 0;
while (reader.Read())
{
mm = reader.GetInt32(0);
DataGridViewRow fila = new DataGridViewRow();
fila.CreateCells(dataGridView1);
fila.Cells[0].Value = datos[0];
fila.Cells[1].Value = Convert.ToDouble(datos[1]);
fila.Cells[2].Value = Convert.ToDouble(datos[2]);
fila.Cells[3].Value = Convert.ToDouble(datos[3]);
fila.Cells[4].Value = umbral;
fila.Cells[5].Value = Math.Round(Convert.ToDouble(mm)/ Convert.ToDouble(datos[4])*100,4);
dataGridView1.Rows.Add(fila);
a = a + 1;
}
}
}
catch (Exception ex)
{
Console.WriteLine("OLEDB Connection FAILED: " + ex.Message);
}