Home > Back-end >  Searching for words in a sentence with c# in the database
Searching for words in a sentence with c# in the database

Time:02-27

Hi I am trying to write a desktop program using c# and visual sutdio. What I want to do in the program; searching inside a column of the database table I have and sorting the records that match it. I want to do the search criteria with the like command, for example, in the patient name table in the hospital database, sort those whose name contains the letters ABC. I want this

(Select *from patient where patient_name like'"   comboBox1.Text   "')

value to be a rule that I set, not from combobox. I want to do a search like

(Select *from patient where patient_name like '"  ABC "')

I will give an example to explain my problem more clearly, I want to use this command, which works in Access, in visual studio.

select patient_name from patient where patient_name like '*abc*';

How can I do this in visual studio?

CodePudding user response:

 public string 
PatientName = "abc";
        public void fill_combobox()
        {
            connection.Open();
            OleDbCommand command = new OleDbCommand("SELECT Patient_name from Patient where Patient_name like  '%"   @PatientName   "%' and patient_old='3'  ", connection);
            OleDbDataReader data = komut.ExecuteReader();
            while (data.Read())
            {
                comboBox1.Items.Add(data[0]);
            }
            connection.Close();
        }

CodePudding user response:

select * from patient where patient_name like '%" textbox1.Text "%'

  • Related