How to access a linked table in access via C#

Asked

Viewed 256 times

0

I wonder if there is any way to make a query in an Access file, but not in a normal table created in Access but a linked file (in this example a txt).

The error you made when I selected 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 query items. I don’t want to insert 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();
        }
    }
    
  • Enter the code and give more information so we can help you.

  • Ready. Added

  • Look at this: string SQL2 = "select ceco, ordem, endereco_cliente, municipio_cliente where endereco cliente like '{0}'"; Where is the from?

  • I made a mistake right there, but it doesn’t even get to this part of the code. When it comes to da.Fill(dt); he already fails.

  • Exists the table TB_tempos_medios? Bad name for table. Is this really the code that is giving error? Give more details about the error.

  • There is the table yes. This ai is a text file that is linked as Table in Access. It does everything until actually searching for the table. I believe he can not find the linked table, only tables really created by access, what I want to know.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.