Hi i am making a combobox multi search. I have a table and coloums like studentid,Fullname,lastname which i have populated into the combobox. Beside the combobox i have textbox. The function i am trying to create is the user selects the colums he wants and enter the search text in the seach txtbox and this the code

string userInput = searchOptionCBX.SelectedItem.ToString().Trim();
            string search_query = "select firstname,lastname,phone from Student_Admission_Table where '" + userInput + "' = '" + searchTbx.Text + "' ";
            student_data_adapter.SelectCommand = new SqlCommand(search_query,connection.SqlConnect());
            student_data_adapter.Fill(studentdataset);
            ResultGRIDview.DataSource = studentdataset.Tables[0];

but i get a empty girdview

1. are you sure you did select an item in comboBox?
2. about sql where clause: are you sure label3.Text property holds same column name as its in the dataBase?
2.1 and if the searchTbx.Text property holds the name that exists in that column?

If any of these 3 questions will be answered as negative, your dataset will be empty (and so will be gridview)!!

Otherwise code look clean - no errors found.
Check the code step by step and slowely - you might find any glitch.

Hi sorry i just added label to check if i am getting the right text.Now i have chaged the code, I have replaced label.text with userInput. All the doubts u have i have done them
i have posted the desgin in the text document

used breakpoint to fix the problem:)
should be " + userInput+ " and not '" + userInput + "' becuse the the query is looking for column 'userInput' instead for userInput

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.