How to Iterate through WebControls And Build Dynamic Query

  • Thread starter Thread starter Mona Syed
  • Start date Start date
M

Mona Syed

Hello,

I have a Web Form with Labels, Textboxes etc. where the user enters
information to specify which fields to include in a sql search query. The
questions I have are:

Q1. How do I iterate through all the controls on my form (Textboxes only)
to pick out the search arguments the user provides in the TextBoxes ?

Q2. Then build a dynamic SQL Query such as "Select * from XYZ.Database
Where Database.Column1 Equal to the value the user entered in TextBox1 And
Database.Column5 equal TextBox2 And.And..etc. etc. ?

Thank you in advance for your help.


Best Regards,
Mona Syed
 
you will need to iterate thru the forms collection. as you iterate you will
cast the control to the appropriate type and extract the selected text to
build your query
 
Back
Top