title: How to check if data already exists in database in c#
body: <pre><code>private int AddRecordCategory()
  {
          AdminAllCategory aAdminAllCategory = new AdminAllCategory();
          AdminAllCategoryBLL allCategoryBLL = new AdminAllCategoryBLL();
  
          int Action = 0;
  
          try
          {
              if (CategoryID &gt; 0)
              {
                  aAdminAllCategory.CategoryId = Convert.ToInt32(CategoryIdtxt.Text);
              }
              else
              {
                  //CategoryGateway objCategoryGateway = new CategoryGateway();
                  string columnName = "CategoryID";
                  string tableName = "Deal.Category";
                  aAdminAllCategory.CategoryId = allCategoryBLL.MaxId(columnName, tableName) + 1;
              }
  
              aAdminAllCategory.Category = BanglaCategory.Text;
              aAdminAllCategory.CategoryEng = EnglishCategory.Text;
              aAdminAllCategory.IsActive = Convert.ToInt32(IsActive.Text);
              aAdminAllCategory.IsHit = Convert.ToInt32(HitDropDown.Text);
              aAdminAllCategory.OrderBy = Convert.ToInt32(OrderBy.Text);
  
              if (Hit.Text != "")
              {
                  aAdminAllCategory.hit = Convert.ToInt32(Hit.Text);
              }
              else
              {
                  aAdminAllCategory.hit = 0;
              }
  
              aAdminAllCategory.MetaKeyword = metaKeyWord.InnerText;
              aAdminAllCategory.MetaDescription = MetaDescription.InnerText;
              aAdminAllCategory.VisibleInDevice = Convert.ToInt32(IsVisible.SelectedValue);
              aAdminAllCategory.AppColorCode = AppColorCode.Text;
  
              aAdminAllCategory.CategoryTitleBng = BngPageTitle.Text;
              aAdminAllCategory.CategoryTitleEng = EngPageTitle.Text;
  
              Action = allCategoryBLL.InsertCategory(aAdminAllCategory);
          }
          catch (Exception ex)
          {
              lblSystemMessage.Text = "Warning!!Contact With IT";
          }
  
          return Action;
  }
  </code></pre>
  
  <p>Here I want to save these attributes in database but want to see if <code>CategoryTitleEng</code> and <code>CategoryTitleBng</code> properties  are saved in database before these column are saved. Then that will show a message like: </p>
  
  <blockquote>
    <p>these property are already exists.</p>
  </blockquote>
  
  <p>The gateway and stored procedure are shown below .....</p>
  
  <pre><code>public int AddRecord_Category(AdminAllCategory aAdminAllCategory)
  {
      int intActionResult = 0;
      int isActive = 1;
      //int isDeleted = 0;
  
      try
      {
          OpenConnection();
          ArrayList arlSqlParameters = new ArrayList();
          arlSqlParameters.Add(new SqlParameter("@CategoryID", aAdminAllCategory.CategoryId));
          arlSqlParameters.Add(new SqlParameter("@Category", aAdminAllCategory.Category));
          arlSqlParameters.Add(new SqlParameter("@IsHit", aAdminAllCategory.IsHit));
          arlSqlParameters.Add(new SqlParameter("@IsActive", aAdminAllCategory.IsActive));
          arlSqlParameters.Add(new SqlParameter("@OrderBy", aAdminAllCategory.OrderBy));
          arlSqlParameters.Add(new SqlParameter("@CategoryEng", aAdminAllCategory.CategoryEng));
          arlSqlParameters.Add(new SqlParameter("@MetaKeyword", aAdminAllCategory.MetaKeyword));
          arlSqlParameters.Add(new SqlParameter("@MetaDescription", aAdminAllCategory.MetaDescription));
          arlSqlParameters.Add(new SqlParameter("@VisibleInDevice", aAdminAllCategory.VisibleInDevice));
          arlSqlParameters.Add(new SqlParameter("@AppColorCode", aAdminAllCategory.AppColorCode));
          arlSqlParameters.Add(new SqlParameter("@CategoryTitleEng",aAdminAllCategory.CategoryTitleEng));
          arlSqlParameters.Add(new SqlParameter("@CategoryTitleBng", aAdminAllCategory.CategoryTitleBng));
  
              intActionResult = this.ExecuteActionQuery("Deal.USP_AddDealsCategory", arlSqlParameters);
  
      }
      catch (Exception ex)
      {
      }
      finally
      {
          CloseConnection();
      }
  
      return intActionResult;
  }
  
  CREATE PROCEDURE [Deal].[USP_AddDealsCategory]
  (
      @CategoryID int,
      @Category nvarchar(150),
      @IsActive int,
      @IsHit int,
      @OrderBy int,
      @CategoryEng varchar(150),
      @MetaKeyword varchar(500),
      @MetaDescription varchar(500),
      @VisibleInDevice int = 0,
      @AppColorCode varchar(50) = '',
      @CategoryTitleEng varchar(200),
      @CategoryTitleBng nvarchar(200),
      @MetaKeywordBng nvarchar(200),
      @MetaDescriptionBng nvarchar(200)
  ) 
  AS
  BEGIN       
  Insert into Deal.Category
  (CategoryID,Category,IsActive,IsHit,OrderBy,Hit,CategoryEng,MetaKeyword,MetaDescription,VisibleInDevice,AppColorCode,CategoryTitleEng,CategoryTitleBng,MetaKeywordBng,MetaDescriptionBng)
  Values(@CategoryID,@Category,@IsActive,@IsHit,@OrderBy,0,@CategoryEng,@MetaKeyword,@MetaDescription,@VisibleInDevice,@AppColorCode,@CategoryTitleEng,@CategoryTitleBng,@MetaKeywordBng,@MetaDescriptionBng)
  END 
  </code></pre>