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.
C# Sqlite Search Multiple Tables
-
03-10-2022 - |
Pergunta
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();
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow