0

I'm currently working on a project with an access 2010 DB and was wondering if you can create a store procedure in this without a server.

I have been looking at other example on stackoverflow but they all seem to be event procedures. I just want to create a simple select statement that I can later on call in c# as a procedure.

Any examples or links would be helpful.

Bruno Lopes
  • 2,917
  • 1
  • 27
  • 38
user3063540
  • 105
  • 7

1 Answers1

0

You could simply create a query in MS-Access and call it from your C# code using CommandType.StoredProcedure.

Suppose you have a table named Customer and you create a query with the Access User Interface called Customers_FindAll, this query contains simply a SELECT * FROM Customers ORDER BY custCode command. (Parameter can also be specified and passed)

In C# you recall this query with

using(OleDbConnection cn = new OleDbConnection(connstring))
using(OleDbCommand cmd = new OleDbCommand("Customers_FindAll", cn))
{
     cn.Open();
     cmd.CommandType = CommandType.StoredProcedure;
     using(OleDbDataReader reader = cmd.ExecuteReader())
     {
          while(reader.Read())
          {
              // use the reader data.....
          }
     }
}
Steve
  • 213,761
  • 22
  • 232
  • 286
  • Sorry to be trouble but from this code how would i then set an input and output like i want the user to enter a word for a search & output the results in a list – user3063540 Mar 10 '14 at 13:52
  • Define parameters for your query with the Access User Interface then change your query to add a WHERE statement and use the parameters defined in access, in C# add the values to be used for the parameters to the OleDbCommand parameters collection. As you can see there is a lot to explain and perhaps it is better to start with a simple code that works, then add complexity and ask a new question about the new problems. :-) – Steve Mar 10 '14 at 13:59