Question

I'm tring to search for a value in multiple Sqlite tables and return the row where the value is found. But my code only works if the value is in the last table i search.

   SetConnection();
    sql_con.Open();
    sql_cmd = sql_con.CreateCommand();
    dataGridView1.DataSource = "";
    try
    {
        string comando = "SELECT UFE_SG, lOG_NO FROM log_logradouro where cep ='" + maskedTextBoxCep.Text + "'";
        DB = new SQLiteDataAdapter(comando, sql_con);
    }
    catch (SystemException e)
    {
    }
                try
    {
        string comando = "SELECT UFE_SG, lOc_NO FROM log_localidade where cep ='" + maskedTextBoxCep.Text + "'";
        DB = new SQLiteDataAdapter(comando, sql_con);
    }
    catch (SystemException e)
                {

                }
    try
    {
        string comando = "SELECT UFE_SG, CPC_NO FROM log_cpc where cep ='" + maskedTextBoxCep.Text + "'";
        DB = new SQLiteDataAdapter(comando, sql_con);
    }
    catch (SystemException e)
    {
    }

    DS.Reset();
    DB.Fill(DS);
    DT = DS.Tables[0];
    dataGridView1.DataSource = DT;
    sql_con.Close();
Was it helpful?

Solution

It looks like you're overwriting the DB object in each try/catch block instead of executing the query and checking for results with each command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top