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 8363281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:08:23+00:00 2026-06-09T12:08:23+00:00

I have a insert stored procedure and I want to check whether the email

  • 0

I have a insert stored procedure and I want to check whether the email already exists or not if exists I have to show an error to the user but how to throw the error and catch it in the code behind?

CREATE procedure [dbo].[SP_ProfileRegMaster]
    @UserId Varchar(50),
    @FirstName Varchar(50)
    @EmailID varchar (50)
    @result int out)
AS
BEGIN
    IF EXISTS (SELECT EmailId FROM Profile_Master WHERE EmailId = @EmailId)
    BEGIN
        SET @result = 0
    ELSE
       RAISERROR ('Email address does not exist.', 1, 1)
END

C# code:

result = cmd1.Parameters.Add("@result", System.Data.SqlDbType.Int);
result.Direction = System.Data.ParameterDirection.Output;
  • 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-06-09T12:08:24+00:00Added an answer on June 9, 2026 at 12:08 pm

    As I mentioned in my comment, I’d not use RAISERROR() in your case. You could do something like this:

    Stored Procedure

    CREATE procedure [dbo].[SP_ProfileRegMaster]
      @UserId  Varchar(50),
      @FirstName  Varchar(50)
      @EmailID varchar (50))
    AS BEGIN
      if exists(select EmailId from Profile_Master where EmailId=@EmailId)
      begin
        return 0
      else
        return 1
      end
    end
    

    C# code

    SqlConnection conn = new SqlConnection(getConnectionString())
    SqlCommand cmd = new SqlCommand("SP_ProfileRegMaster", conn);
    cmd.CommandType = CommandType.StoredProcedure;
    
    // Pass parameters to Stored Proc...
    
    // Add one more parameter to store the Return Value
    var returnParameter = cmd.Parameters.Add("@ReturnVal", SqlDbType.Int);
    returnParameter.Direction = ParameterDirection.ReturnValue;
    
    conn.Open();
    cmd.ExecuteNonQuery();
    // Retrieve the return value
    var result = returnParameter.Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a stored procedure with 4 insert and i have this
I have a stored procedure that inserts a user into a table but I
I currently have a stored procedure in which I want to insert new rows
I'm using devexpress and i have two problems. My insert stored procedure work fine.
HI, I have an insert statement in a Stored Procedure that requires the value
I have a stored procedure with multiple insert/select statements. Let's say I'm using the
I have a stored procedure which is called inside a trigger on Insert/Update/Delete. The
Say I have a stored procedure consisting of several separate SELECT, INSERT, UPDATE and
I have inside a stored procedure: INSERT INTO SitesCategories(SiteID, CategoryID) VALUES(@SITEID, @TempCId); This insert
I have an insert stored procedure which takes many parameters - 2 of them

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.