I have a WCF service which needs to insert into a SQL 2005 log table after successfully executing one of its methods.
Using EnterpriseLibrary, I found some sample code which resembles this:
public static void SaveActivity(string sSomeString)
{
Database db = DatabaseFactory.CreateDatabase();
string sInsert = @"INSERT INTO ActivityTable (SomeString) VALUES @SomeString";
DbCommand dbInsert = (DbCommand)db.ExecuteScalar(sInsert);
db.AddInParameter(dbInsert, "SomeString", DbType.String, sSomeString;
}
With this code won't the input parameter be ignored, since it's defined after the ExecuteScalar method?!
Finally, with best practices in mind, instead of doing an INSERT, should I create a stored proc and pass parameters to it?