Search code examples
c#sqlwinformsms-accessquery-expressions

how to modify query expression for flexible results - Win Forms C#


Introduction

I am working with winforms.The query expression i have created to search on user input, return results correctly.

Query Expression

public static readonly string SqlSearchPlotByName = "Select " +
" PropertyId, Contact, Location, Street, Status, City, CreatedDate, Demand, Phase, Area, Corner,Commercial,CompanyName,OwnerName,OwnerAddress,OwnerPhone,Email,Web" +
" From Property Where OwnerName LIKE @OwnerName";

Sql Command Parameters

// name is user input
  dataAdapter.SelectCommand.Parameters.AddWithValue("@OwnerName", name);

Problem

I am having problem to modify the query expression for flexible results.

For example : when search "jo", the result must be including joe, john, johnny etc.

Can someone please help me modify the query, or any reference/help?

Thanks for your time.


Solution

  • dataAdapter.SelectCommand.Parameters.AddWithValue("@OwnerName", name);
    

    use it like

    dataAdapter.SelectCommand.Parameters.AddWithValue("@OwnerName", name+"%");