【问题标题】:How to Execute an Object Query in MS Access using C#?如何使用 C# 在 MS Access 中执行对象查询?
【发布时间】:2015-12-19 20:41:30
【问题描述】:

我在 MS Access 中有一个名为“getLicense”的对象查询,它将执行以下操作:

SELECT * FROM tblLicense;

在我的 C# WinForm 应用程序中,我试图通过这些代码在 MS Access 中执行“getLicense”对象查询:

/***This does not work***/
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "getLicense";
myReader = myCommand.ExecuteReader();
myReader.Read();
/************************/

/****This is working*****/
myCommand.CommandType = CommandType.Text;
myCommand.CommandText = "SELECT * FROM tblLicense";
myReader = myCommand.ExecuteReader();
myReader.Read();
/************************/

我想通过对象查询管理我在 MS Access DB 中的查询 而不是在 C# 中的硬编码查询中,这就是我尝试使用 CommandType.StoredProcedure 的原因。

这里是例外

ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] SQL 语句无效;预期为“DELETE”、“INSERT”、“PROCEDURE”、“SELECT”或“UPDATE”。

【问题讨论】:

标签: c# sql winforms


【解决方案1】:

这就像一个 MSSQL Server 存储过程的执行,我已经替换了:

myCommand.CommandText = "getLicense";

用这个:

myCommand.CommandText = "EXEC getLicense";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-13
    • 1970-01-01
    • 2019-12-04
    相关资源
    最近更新 更多