How to access a linked table in access via C #

0

I would like to know if there is any way to do a query in an Access file, but not in a normal table created in Access but rather a linked file (in this example a txt).

The error I made when I made the select was as follows:

O mecanismo de banco de dados do Microsoft Office Access não encontrou a tabela de entrada ou consulta 'Tabela'. Verifique se ela existe e se seu nome está digitado corretamente.

NOTE: I just want to check items. I do not want to enter anything.

  • Edit - Code

    private void btnBuscar_Click(object sender, EventArgs e)
    {
        string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Triagem\TRIAGEM.accdb;Persist Security Info=False;";
        OleDbConnection conn = new OleDbConnection(connectionString);
    
        try
        {
            conn.Open();
    
            string SQL = "select endereco_cliente from TB_tempos_medios where ordem = '" + txtOrdem.Text + "'";
            OleDbDataAdapter da = new OleDbDataAdapter(SQL, conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
    
            string enderecoCliente = null;
    
            if (dt.Rows.Count > 0)
            {
                DataRow dtRow = dt.Rows[0];
                enderecoCliente = dtRow["endereco_cliente"].ToString();
    
                string SQL2 = "select ceco, ordem, endereco_cliente, municipio_cliente where endereco cliente like '{0}'";
                SQL2 = string.Format(SQL2, enderecoCliente);
    
                OleDbDataAdapter da2 = new OleDbDataAdapter(SQL2, conn);
                DataTable dt2 = new DataTable();
                da.Fill(dt2);
    
                gdvInfos.DataSource = dt2;
            }
            else
            {
                MessageBox.Show("Por favor, informa uma ordem válida.", "Ordem não encontrada", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        catch (Exception ex)
        {
            throw;
        }
        finally
        {
            conn.Close();
        }
    }
    
asked by anonymous 15.12.2015 / 14:28

0 answers