I think you should do it at SQL side.
IF NOT EXISTS(SELECT COLUMNNAME FROM TABLENAME WHERE COLUMNNAME=@COLUMNNAME)
BEGIN
SELECT 'Record saved successfully' as Response
END
ELSE
BEGIN
SELECT 'This value exists already' as Response
END
OR
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DelhiEMP;Integrated Security=True");
con.Open();
string query = "select code from countermaster2 where code = @code";
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataSet ds = new DataSet();
if(ds.Table[0].Rows.Count > 0)
{
MessageBox.Show("Code is already exsist");
}
else
{
MessageBox.Show("enter new records");
}
Excuse Typo mistakes
Let me know if still you have any query or concern for same.