MS-Access查询语法

时间:2015-08-30 16:24:52

标签: c# ms-access ms-access-2007

我有mysql的背景。现在我正在使用C#进行MS-Access。我试过跟踪sql查询,但它抛出异常

查询1:

String strSql = "Select * from Employees orderby EmployeeID desc limit 1;";
OleDbDataAdapter adapter = new OleDbDataAdapter(strSql, conn);
adapter.Fill(dt);

String strSql = "Select * from Employees orderby EmployeeID asc limit 1;";
OleDbDataAdapter adapter = new OleDbDataAdapter(strSql, conn);
adapter.Fill(dt);

常见例外1:

Additional information: Syntax error in FROM clause.

查询2:

String strSql = "select * from Employees where EmployeeID = (select min(EmployeeID) from Employees where EmployeeID < '" + Int64.Parse(this.txtBoxID.Text) + "');";
OleDbDataAdapter adapter = new OleDbDataAdapter(strSql, conn);
adapter.Fill(dt);

String strSql = "select * from Employees where EmployeeID = (select min(EmployeeID) from Employees where EmployeeID > '" + Int64.Parse(this.txtBoxID.Text) + "');";
OleDbDataAdapter adapter = new OleDbDataAdapter(strSql, conn);
adapter.Fill(dt);

常见例外2:

Additional information: Data type mismatch in criteria expression.

我的数据库位于

之下

enter image description here

2 个答案:

答案 0 :(得分:3)

为什么不使用查询设计器在访问中创建查询,更改为sql视图,然后将sql复制回代码?

另外,我认为你必须使用访问权限 -

SELECT TOP 1 * from Employees;

而不是

Select * from Employees limit 1;

答案 1 :(得分:0)

查询1:

Select * from Employees order by EmployeeID ...