I have an application that monitors a process and "learns" exceptions, by adding them to a DB. The process to gather the errors/exceptions is pretty solid, but not the storing on the DB side. What I want to accomplish is something like
public int GetErrorId(string StringToClassify)
{
sql = "SELECT [id] FROM [DBNAME].[dbo].[ERRORS] WHERE [ErrorString] = (@StringToClassify)";
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.Add("@StringToClassify", SqlDbType.VarChar);
cmd.Parameters["@StringToClassify"].Value = StringToClassify;
connection.Open();
Object result = cmd.ExecuteScalar();
if (result == null)
sysId = AddError(StringToClassify);
else
sysId = Int32.Parse(result.ToString());
}
}
How do I implement the AddError(string s) function? Something that inserts a record and returns the ID of the inserted record?