Home > front end >  System.Data.OleDB 'Data type mismatch in criteria expression.'
System.Data.OleDB 'Data type mismatch in criteria expression.'

Time:06-02

I've been trying to get different columns from different tables (Access database) into one DataTable. The query / command is correct, but the adapter causes an error

System.Data.OleDb.OleDbException:'Data type mismatch in criteria expression.'

The Command is

SELECT tab_agend.ID, tab_teams.Descricao, tab_agend.idtask 
FROM tab_teams 
INNER JOIN tab_agend ON tab_teams.ID = tab_agend.idequipa;

It does work on Access but Visual Studio throws an error on the line:

adapter.Fill(dset, "table");

Full code:

string query;

if (Tabela == "tab_agend") 
{  
    query = "SELECT tab_agend.ID, tab_teams.Descricao, tab_agend.idtask "   
            " FROM tab_teams "   
            " INNER JOIN tab_agend ON tab_teams.ID = tab_agend.idequipa;";
} 
else 
{  
     query = "SELECT * FROM "   Tabela;
}

dset.Reset();

adapter = new OleDbDataAdapter(query, connection);
adapter.Fill(dset, "table");

CodePudding user response:

I got the right query by adding a DataSet File on the project and doing everything "visually"

Image of DataSet1.xsd (DataSet File)

SELECT 
    tab_places.Localizacao, 
    tab_subtasks.[Desc], tab_subtasks.Type, 
    tab_tasks.*, tab_subtasks.IDTask
FROM 
    ((tab_tasks 
LEFT JOIN 
    tab_places ON tab_tasks.IDPlace = tab_places.ID) 
LEFT JOIN 
    tab_subtasks ON tab_tasks.ID = tab_subtasks.IDTask)

The code to call the adapter and fill the Datagrid is:

DataSet1TableAdapters.DataTable1TableAdapter dadapter = new DataSet1TableAdapters.DataTable1TableAdapter();

DataSet1.DataTable1DataTable dt = new DataSet1.DataTable1DataTable();

dadapter.Fill(dt);

sfDataGrid1.DataSource = dt;
  • Related