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