Here is the algorithm:
1. Read the textbox value
2. Send the value to database, using stored procedure execute the below query to check whether the values exist or not:
declare @itexists as int;
if exists(select * from MyTable where Barcode=@barcode)
set @itexists=1;
else
set @itexists=0;
print @itexists;
3. Get the result using ExecuteScalar and perform rest of the operations based on this value
In your case. just modify your database code as below:
public bool CompareBarcode(string barcode)
{
using (SqlConnection conn = new SqlConnection(ConnectionSTring))
{
SqlCommand cmd = new SqlCommand("uspCheckBarcode", conn);
cmd .CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@barcode", barcode);
return Convert.ToBoolean(cmd.ExecuteScalar());
}