Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 502511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:17:56+00:00 2026-05-13T06:17:56+00:00

I have an application that monitors a process and learns exceptions, by adding them

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:17:56+00:00Added an answer on May 13, 2026 at 6:17 am

    If there is no other logic that depends on whether the string existed or not, why not make it into a stored procedure that does an INSERT if it’s present, or an UPDATE if it’s not? Then return the ID either way.

    If you’re using SQL Server 2008, this is a perfect opportunity to use the MERGE statement.

    Here’s an example of a stored procedure, utilizing the MERGE statement, that will “upsert”, modified from this example.

    CREATE PROC dbo.usp_VendorUpsert
    (
         @stringID INT OUTPUT,
         @stringValue VARCHAR(80)
    )
    AS
    BEGIN
    
         SET NOCOUNT ON;
    
         MERGE dbo.Errors as target
           USING (SELECT @stringValue) AS source(ErrorString)
           ON target.ErrorString = source.ErrorString
    
         WHEN NOT MATCHED THEN
         INSERT (ErrorString) VALUES (@stringValue)
    
         WHEN MATCHED THEN
         UPDATE SET @stringID = id;
    
         // Get the id from the insert or the update.
         SET @stringID = COALESCE(SCOPE_IDENTITY(), @stringID);
    
    END
    
    RETURN
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Turns out it is a "switch" on the Apple side… May 16, 2026 at 11:59 am
  • Editorial Team
    Editorial Team added an answer jQuery has certainly made the task a LOT more manageable.… May 16, 2026 at 11:59 am
  • Editorial Team
    Editorial Team added an answer There is no built-in mechanism for exporting the installed extensions… May 16, 2026 at 11:59 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a PHP-based web application that monitors the status of a process and
I have a server application that spins up and monitors about 8 separate processes
I am creating an application that monitors a select group of programs and restarts
I have a VB6 application that still references some old VB5 libraries (dll, vbr,
I have a legacy VB6 application that was built using MSDE. As many client's
I'm trying to write an application that runs as a daemon and monitors running
I have a VB.NET windows application that when I debug it, it opens the
I have application that runs non stop in the background on a dedicated remote
I have an application that I'm developing in Visual Studio 2010 that utilizes a
I have an application that uses an external jar. I used eclipse and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.