Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Run SQL command if text box are not empty

$
0
0

Hi Guys quick question,

I have quick question. I have 4 textbox's which searches data from a data base. But what i want to do is if the user only enters a some data in to one or two of the textbox's to search a query and retrieve the record that matches some of the text using the"LIKE " command . The way i was going to do it was use a lot of if else statements like  

            if (tbDocID.Text != null)
            {
                searchAllCom = new OleDbCommand("SELECT * FROM Doctors WHERE Doctors_ID =" +tbDocID.Text+" ", conToDataBase);
            }

            else if (tbForname.Text != null)
            {
                searchAllCom = new OleDbCommand("SELECT * FROM Doctors WHERE Forename LIKE'" + tbForname.Text + "%'", conToDataBase);
            }

But i know there must be a better and cleaner way to do this . So any idea would be appreicated

Thanks


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>