Search code examples
c#sqlsplitfilteringwhere-in

Is there a way to split a list in the following format : 'string1', 'string2', 'string3',


I need to perform a filter to my existing XtraReport and I want to see only some specific records which I have their ID's.

When I execute following code it is applied successfully.

XtraReportOrder report = new XtraReportOrder();
report.FilterString = "orderId IN ('11092', '11093')";
report.ShowPreviewDialog();

I want to use sth like this,

report.FilterString = "orderId IN ("+MyList.ToConvertSthConvinient+")";

Solution

  • You can use a combination of String.Join, LINQ and the string interpolation feature:

    report.FilterString = $"orderId IN ({String.Join(", ", MyList.Select(id => $"'{id}'"))})";