Search code examples
vb.nett-sqlsql-like

textbox matching pattern from database table


I have a name textbox and I want to find any names included in the typed text in the database table patient details name column. I know how to use LIKE operator if you know the letters you want the search to start/end with etc. but this time I want textbox. I think my issue is with the quotations; I tried to play around with it but it didn't work!

From x in PatientDetails where ( x.Patient_Name Like  '%" Textbox1.Text "%' )

For example: If a Patient name in the database is: John Matt

and a user typed Matt, the above record for John Matt should be returned.

P.S I tried looking it up in Google but it mostly discuss characters not entered text box Thank you all.


Solution

  • Something like this would do

    C#

    var query = (from x in PatientDetails
                 where x.Patient_Name.Contains(Textbox1.Text)
                 select x).ToList();
    

    VB.NET - Converted using CodeConverter

    Dim query = (From x In PatientDetails Where 
                 x.Patient_Name.Contains(Textbox1.Text)x).ToList()