954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to use stored procedure in access

Hi all,
Can anybody help me...How to create insert store procedure in access db with c# windows application.

bhagawatshinde
Posting Whiz
315 posts since Sep 2010
Reputation Points: 21
Solved Threads: 22
 

Here is a technique for creating a stored procedure in an Access database using C# code.

//using System.Data.Odbc;
      private static bool CreateProc(ref string strError)
      {
         bool blnRetVal = true;

         string strSQL =
            "create proc InsTestNum2(inTestNum) AS INSERT INTO Test_Detail(test_no) values(inTestNum)";

         try
         {
            using (OdbcConnection conn = new OdbcConnection("DSN=DW_ACCESS"))
            {
               conn.Open();
               (new OdbcCommand(strSQL, conn)).ExecuteNonQuery();
               conn.Close();
            }
         }
         catch (Exception exc)
         {
            blnRetVal = false;
            strError = exc.Message;
         }

         return blnRetVal;
      }


This requires the DSN to be registered in the OdbcAdministrator
Control Panel / Administrative Tools / Data Sources (ODBC)

Also, it will need to be customized for your particular database.

This can be called from any type of app with something like this:

//using System.Diagnostics;
         string strError = "";

         if (!CreateProc(ref strError))
         {
            Trace.WriteLine("Could not create proc: " + strError);
            return;
         }
thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

Thanks thines01 for your valuable reply. It's really helped

bhagawatshinde
Posting Whiz
315 posts since Sep 2010
Reputation Points: 21
Solved Threads: 22
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You