0

I have an Object Query in MS Access named "getLicense" that will execute the following:

SELECT * FROM tblLicense;

In my C# WinForm Application, I'm trying to execute the "getLicense" Object Query in MS Access through these codes:

/***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();
/************************/

I want to manage my Queries in MS Access DB through Object Queries and not in the hard coded query in C# that's why I'm trying to use the CommandType.StoredProcedure.

Here is the exception

ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

3
  • do you get an exception? if so, what is the exception you get? Commented Mar 29, 2015 at 7:22
  • possible duplicate of OleDbCommand Stored Procedure Cannot Find Access Query Commented Mar 29, 2015 at 7:23
  • 1
    Did you try myCommand.CommandText = "Exec getLicense" with commandtype as text Commented Mar 29, 2015 at 7:28

1 Answer 1

2

It is like an execution of the MSSQL Server Stored Procedure, I have replaced the:

myCommand.CommandText = "getLicense";

with this:

myCommand.CommandText = "EXEC getLicense";

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.