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

Recommended Answers

All 2 Replies

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)";

            using (OdbcConnection conn = new OdbcConnection("DSN=DW_ACCESS"))
               (new OdbcCommand(strSQL, conn)).ExecuteNonQuery();
         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);

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.