How to know if a DataGridView
shows the same information every time you execute an SQL query?
private void timer1_Tick(object sender, EventArgs e)
{
data.DataSource = "";
/* Cargar datos */
data.DataSource = CCarsData.ConexionDB.CargarTable();
/* Set Grid */
setdv();
comparar();
}
private void comparar()
{
timer1.Enabled = false;
foreach (DataGridViewRow Row in data.Rows)
{
string Valor = Convert.ToString(Row.Cells[0].Value);
string status = Convert.ToString(Row.Cells[2].Value);
foreach(DataGridViewRow row2 in data2.Rows)
{
string Valor2 = Convert.ToString(row2.Cells[0].Value);
string status2 = Convert.ToString(row2.Cells[2].Value);
if (Valor == Valor2)
{
if (status == "DISPONIBLE" && status2 == "SERVICIO")
{
MessageBox.Show("El vehiculo " + Row.Cells[0].Value.ToString() + " se encuentra disponible", "Flota", MessageBoxButtons.OK);
}
}
}
}
data2.DataSource = "";
/* Cargar datos */
data2.DataSource = CCarsData.ConexionDB.CargarTableServicio();
setdv2();
timer1.Enabled = true;
}
The grid1
is loaded with the articles table, and the grid2
is loaded with the articles that have service status.
My application is merely informative and does not perform CRUD operations on the database.
***** EDIT ****
I made some changes to the code since in principle it was redundant.
grid1
charge all articles grid2
charge only items with "SERVICE" status That is:
private void Form1_Load(object sender, EventArgs e)
{
/* Cargar datos */
data.DataSource = CCarsData.ConexionDB.CargarTable();
data2.DataSource = CCarsData.ConexionDB.CargarTableServicio();
}
When starting the timer
just refresh the grid1
and compare with the'grid2'
private void compare () { timer1.Enabled = false;
foreach (DataGridViewRow Row in data.Rows)
{
string Valor = Convert.ToString(Row.Cells[0].Value);
string status = Convert.ToString(Row.Cells[2].Value);
foreach(DataGridViewRow row2 in data2.Rows)
{
string Valor2 = Convert.ToString(row2.Cells[0].Value);
string status2 = Convert.ToString(row2.Cells[2].Value);
if (Valor == Valor2)
{
if (status == "DISPONIBLE" && status2 == "SERVICIO")
{
MessageBox.Show("El vehiculo " + Row.Cells[0].Value.ToString() + " se encuentra disponible", "Flota", MessageBoxButtons.OK);
}
}
}
}
data2.DataSource = "";
/* Cargar datos */
data2.DataSource = CCarsData.ConexionDB.CargarTableServicio();
setdv2();
timer1.Enabled = true;
}
With this I only make a comparison between all the articles and only those that are with service status