System.Data.OleDB 'Data type mismatch in criteria expression.'
System.Data.OleDB 'Data type mismatch in criteria expression.'
我一直在尝试将不同表(Access 数据库)中的不同列放入一个数据表中。查询/命令正确,但适配器导致错误
System.Data.OleDb.OleDbException:'Data type mismatch in criteria expression.'
命令是
SELECT tab_agend.ID, tab_teams.Descricao, tab_agend.idtask
FROM tab_teams
INNER JOIN tab_agend ON tab_teams.ID = tab_agend.idequipa;
它确实适用于 Access,但 Visual Studio 会在以下行引发错误:
adapter.Fill(dset, "table");
完整代码:
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");
我通过在项目上添加数据集文件并“可视化”完成所有操作得到了正确的查询
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)
调用适配器并填充数据网格的代码是:
DataSet1TableAdapters.DataTable1TableAdapter dadapter = new DataSet1TableAdapters.DataTable1TableAdapter();
DataSet1.DataTable1DataTable dt = new DataSet1.DataTable1DataTable();
dadapter.Fill(dt);
sfDataGrid1.DataSource = dt;
我一直在尝试将不同表(Access 数据库)中的不同列放入一个数据表中。查询/命令正确,但适配器导致错误
System.Data.OleDb.OleDbException:'Data type mismatch in criteria expression.'
命令是
SELECT tab_agend.ID, tab_teams.Descricao, tab_agend.idtask
FROM tab_teams
INNER JOIN tab_agend ON tab_teams.ID = tab_agend.idequipa;
它确实适用于 Access,但 Visual Studio 会在以下行引发错误:
adapter.Fill(dset, "table");
完整代码:
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");
我通过在项目上添加数据集文件并“可视化”完成所有操作得到了正确的查询
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)
调用适配器并填充数据网格的代码是:
DataSet1TableAdapters.DataTable1TableAdapter dadapter = new DataSet1TableAdapters.DataTable1TableAdapter();
DataSet1.DataTable1DataTable dt = new DataSet1.DataTable1DataTable();
dadapter.Fill(dt);
sfDataGrid1.DataSource = dt;