-1

I'm making an ODP.NET database application for my school project using wpf. I have a list of checkboxes corresponding to table's columns. Is there a nicer way of building a select statement than just going through a foreach loop?

I've looked into OracleCommandBuilder Class but it didn't seem to have what i was looking for.

private IEnumerable<CheckBox> allC = employeesC = Employees.Children.OfType<CheckBox>();
string selectStatement = "SELECT ";

foreach (CheckBox cb in allC)
{
  if (cb.IsChecked ?? false)
  {
    selectStatement += cb.Content + ", ";
  }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mac501
  • 37
  • 5
  • You may be interested in [SqlKata](https://sqlkata.com/), a library for building SQL statements. – mason May 03 '19 at 20:47

1 Answers1

2

I haven't tried this, but you should be able to do some linq fanciness with that loop and if condition:

string selectStatement = "SELECT " + string.Join(", ", allC
    .Where(c => c.IsChecked.GetValueOrDefault())
    .Select(c => c.Content));
Rufus L
  • 36,127
  • 5
  • 30
  • 43