devxlogo

Create Queries On the Fly

Create Queries On the Fly

Use VB’s string-concatentation operator (&) to incorporate user input into SQL queries at run time. Assume, for example, that cboField is a combo box containing a list of fields in a table, and txtValue is a text box into which the user types a value to search for. Here’s how to create a dynamic query that includes the user’s input:

 sField = cboFieldsValue = txtValueSQL = "SELECT * FROM Table WHERE " & _	sField & " LIKE '" & sValue & "';"

Note that you must surround the search value with quotes if you are searching a text field; no quotes are necessary if the target field contains numeric data./p>

See also  How College Students Can Shape the Future of Tech Responsibility
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist