Skip to content
Loading
  • Abhilash J A
    0
    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:
    1. declare @itexists as int;  
    2.    
    3. if exists(select * from MyTable where Barcode=@barcode)  
    4.     set @itexists=1;  
    5. else  
    6.     set @itexists=0;  
    7.    
    8. 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:
    1. public bool CompareBarcode(string barcode)  
    2.        {  
    3.            using (SqlConnection conn = new SqlConnection(ConnectionSTring))  
    4.            {  
    5.                SqlCommand cmd = new SqlCommand("uspCheckBarcode", conn);  
    6.                cmd .CommandType = CommandType.StoredProcedure;  
    7.                cmd.Parameters.AddWithValue("@barcode", barcode);  
    8.                return Convert.ToBoolean(cmd.ExecuteScalar());  
    9.   
    10.            } 
     
    0