I'm trying to get some data out of Microsoft Acess and check it through MessageBoxes so the user can see if that is the data that he wants but the code its not executing at all. I can't see any of the message boxes and no exceptions are thrown. Below its the code that I put in the Button event. (I've only done the first if, the CNPJ one).
if (TipoConsulta.Text == "CNPJ")
{
try
{
string comando = "SELECT razao_social FROM tblImobiliarias WHERE cnpj ='" + ValorConsulta.Text + "'";
string conn = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=\\\\10.7.41.153\\Apoio\\Davi_Database\\Base_Imo.accdb";
OleDbConnection Connection = new OleDbConnection(conn);
OleDbCommand Command = new OleDbCommand(comando, Connection);
Connection.Open();
OleDbDataReader reader = Command.ExecuteReader();
while (reader.Read())
{
foreach (OleDbDataReader resultado in reader)
{
DialogResult resultadoDialogo;
resultadoDialogo = MessageBox.Show("Encontrada razão social '" + resultado.ToString() + "'.\n Está correto?", "Pesquisa", MessageBoxButtons.YesNo);
if (resultadoDialogo == System.Windows.Forms.DialogResult.Yes)
{
MessageBox.Show("Executado CarregaImobiliaria().");
break;
}
else if (resultadoDialogo == System.Windows.Forms.DialogResult.No)
{
continue;
}
}
}
}
catch (InvalidOperationException)
{
MessageBox.Show("Nada foi encontrado com o CNPJ " + ValorConsulta.Text + ".", "Pesquisa");
}
}
else if (TipoConsulta.Text == "Razão Social")
{
MessageBox.Show("Tipo: Razão Social");
try
{
}
catch (InvalidOperationException)
{
}
}
else if (TipoConsulta.Text == "RGI")
{
MessageBox.Show("Tipo: Sub: RGI");
try
{
}
catch (InvalidOperationException)
{
}
}