gpt4 book ai didi

c# - MS-Access 查询语法

转载 作者:行者123 更新时间:2023-11-30 21:55:27 27 4
gpt4 key购买 nike

我有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

最佳答案

为什么不使用查询设计器在 Access 中创建查询,更改为 sql View ,然后将 sql 复制回您的代码中?

此外,我认为您必须拥有 Access 权限-

SELECT TOP 1 * from Employees;

而不是

Select * from Employees limit 1;

关于c# - MS-Access 查询语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32298703/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com