The newest function in the C# Code Generator is a general purpose Sql funnction that can be used for any non-query sQL command. The code list below is a static version in our general purpose database library.
- CDb.DsnYYYZ is our connection string
- strSql is a valid Sql command
Using the C# Class Generator, the generated code is as follows:
// General purpose Non-Query SQL Command Function
public static bool SqlFunction(stringsqlStr)
{
SqlConnection m_SqlConnection = new SqlConnection(CDb.DsnYYYZ );
SqlCommand m_SqlCommand = new SqlCommand(sqlStr,m_SqlConnection);
try
{
m_SqlConnection.Open();
m_SqlCommand.ExecuteNonQuery();
}
catch (Exception e)
{
return false;
// throw new Exception("Error in SqlFunction-> " + e.ToString());
}
finally
{
m_SqlCommand.Dispose();
m_SqlConnection.Close();
}
return true;
}//end SQLFunction