How to check duplicate records in database through SQL stored procedure by using

Stored Procedure always help to execute group of statement at a time. It saves time and avoids redundancy. This code can be used when unique record has to be inserted in tables of sql. Consistent implementation of logic across applications can be achieved by using stored procedures.

How to check duplicate records in database through SQL stored procedure by using
Description - After calling stored procedure, bool value will be retured which helps you to find whether duplicate records are present in database or not.

public bool CheckDuplicateRecords()
CONN = GetConnection();
//This will open the connection.
CMD = new SqlCommand("yourStoredProcedurename", CONN);
CMD.CommandType = CommandType.StoredProcedure;
CMD.Parameters.Add("@ChkDuplicateRecord", SqlDbType.Char, 1);
CMD.Parameters["@ChkDuplicateRecord"].Direction = ParameterDirection.Output;
bool Is_duplicate = Convert.ToBoolean(CMD.ExecuteNonQuery());
return Is_duplicate;

catch (Exception ex)
throw ex;
//This will close the connection.


This code will help you to connect to database.

public SqlConnection GetConnection()
CONN = new SqlConnection(ConfigurationManager.ConnectionStrings["Keyname"].ToString());
return CONN;

You have to put following code in Web.config

<add name="Keyname" connectionString="Data Source=yourPCname\yourSQLServerInstancename;Initial Catalog=yourDatabaseName;User ID =youruseridcredentials;Password=yourPassword" providerName="System.Data.SqlClient"/>


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: