Use of SqlParameter in SQL LIKE clause not working

前端 未结 4 1195
青春惊慌失措
青春惊慌失措 2020-11-27 14:53

I have the following code:

const string Sql = 
    @\"select distinct [name] 
      from tblCustomers 
      left outer join tblCustomerInfo on tblCustomers.         


        
4条回答
  •  悲哀的现实
    2020-11-27 15:17

    Instead of using:

    const string Sql = 
    @"select distinct [name] 
      from tblCustomers 
      left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId  
      where (tblCustomer.Name LIKE '%@SEARCH%' OR tblCustomerInfo.Info LIKE '%@SEARCH%');";
    

    Use this code:

    const string Sql = 
    @"select distinct [name] 
      from tblCustomers 
      left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId  
      where (tblCustomer.Name LIKE '%' + @SEARCH + '%' OR tblCustomerInfo.Info LIKE '%' + @SEARCH + '%');";
    

提交回复
热议问题