Split form parameters for the query

Stimulsoft Reports.NET discussion
Post Reply
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Split form parameters for the query

Post by Jennypi »

Hi all,

In one of my report's form, users can choose several controls to run their query on:
ID: ...
or Product name: ...
or Comment: ...
or Category: ...
then, depending on their answer, I fill a variable ("query") to complete my SQL query:

Code: Select all

if (TextBoxControl1.Text!="")
{query=query+" and ID="+TextBoxControl1.Text;}
if (ComboBoxControl1.SelectedItem!=null)
{query=query+" and inventaire.[Product_name]='"+ComboBoxControl1.Control.Text+"'";}
if (TextBoxControl2.Text!="")
{query=query+" and Comments='"+TextBoxControl2.Text+"'";}
if (ComboBoxControl2.SelectedItem!=null)
{query=query+" and Category='"+ComboBoxControl2.Control.Text+"'";}
inventaire.Connect();
Now, they're asking me to be able to query multiple IDs.
My idea is that they would type, in the ID field, something like this: "10, 24, 58, 47".
I would like then to split this text field on comas to be able to retrieve the four IDs they want.

How can I do that? With a loop maybe? I don't know how to write a split instruction, same for the loop... :oops:

Thanks for your help!
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Split form parameters for the query

Post by HighAley »

Hello.

You could add a verification if there any coma in the IDs string. And then add code like this:

Code: Select all

if (TextBoxControl1.Text != String.Empty)
    if (TextBoxControl1.Text.IndexOf(",") != -1)
        query += " and ID IN(" + TextBoxControl1.Text + ")";
    else
        query += " and ID=" + TextBoxControl1.Text;
Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Re: Split form parameters for the query

Post by Jennypi »

Working perfectly, thanks a lot!!
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Split form parameters for the query

Post by HighAley »

Hello.

We are always glad to help you.
Let us know if you need any additional help.

Thank you.
Post Reply