0

I really need your expert help :). Expanding on what I have learnt from querying data sets using adapters and filling a Grid View. I need some help on the following task.

I have a SQL Server Database which I am querying using C#. I already have solid working solutions of by a date range, a specific value. However, the business user would like to search by a list of values they provide as input into a form.

Similar to the below: adapter.SelectCommand.Parameters.AddWithValue("@mindate", textBox1.Text);

The input will be taken from a text box or similar form based element. There should be no defined limit to the number of values e.g. I don't want to prevent the user from inputting 100 values for example.

By way of example. User input: doc1.num1.value;doc2.num1.value;doc3.num1.value etc Note: The document number field may contain a full stop. However, each value will be terminated by a ';'

In the above example, we would run the following query: select employee_id, docNumbers from tableName where docNumbers in (inputlist)

And the output would be: Record 1: 1, doc1.num1.value Record 2: 2, doc2.num1.value Record 3: 3, doc3.num1.value

Thanks in advance guys and gals.

Xathras
  • 210
  • 1
  • 5
  • 15
  • please post some code of what you have already tried – Ben Jun 02 '14 at 02:56
  • your question is more likely answered before. Look at this: http://stackoverflow.com/questions/337704/parameterizing-an-sql-in-clause – HengChin Jun 02 '14 at 03:13

1 Answers1

0

I guess what you are looking for is using an IN clause when doing your query.

cs95
  • 379,657
  • 97
  • 704
  • 746
HengChin
  • 583
  • 5
  • 16
  • Thanks again for the link. This option looks like a nice solution to what I want to achieve and better optimized if the user entered a long list: http://stackoverflow.com/a/337907/1510762. I will give that a try :) – Xathras Jun 02 '14 at 03:27
  • Good to heard that. Happy coding. =] – HengChin Jun 02 '14 at 03:32
  • Chinz if I had enough rep I would increment for you. Currently working on this now and will set to solved once I cracked it :) – Xathras Jun 02 '14 at 03:40