Click here to Skip to main content
15,913,396 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created an MS Access Query named GetContactCategory

SQL
select GetCategoryNames(contactId) as CategoryNames from Contacts


The Function GetCategoryNames is the function written in a module of same database.

Now when i call this query in my c# application using ADO.net it throws error.

Following is my c# code

C#
using (OleDbCommand cm = new OleDbCommand())
            {
                cm.Connection = AccessConnection();
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "GetContactCategory";

                cm.Connection.Open();
                using (OleDbDataReader reader = cm.ExecuteReader())//This line throws error
                {
                    //some code
                }
           }


The error which is get Undefined function 'GetCategoryNames' in expression.

what is the problem and whats the solution.
Posted

You can't use VBA functions in a query from outside of Access. Those kind of queries only work when executed inside Access.
 
Share this answer
 
Comments
Maciej Los 21-Dec-14 13:52pm    
Dave, it's partially true. It's possible to use queries, but only with DAO.
Dave Kreskowiak 21-Dec-14 13:58pm    
Who the hell still uses DAO?? :)
Maciej Los 21-Dec-14 14:36pm    
Santa Claus :laugh:
ADO.NET does not supports this kind of functionality. It's possible to use queris togheter with DAO[^] (not recommended, because it's very old).
You need to pass entire code of query to OleDbCmmand.CommandText.

Here is quite interesting tutorial: Using ADO.NET for beginners[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900