I have to implement a filter mechanism that will query a database and return the results to a .rdlc report that displays it in a report viewer. I managed to make it work for single condition queries (by using TableAdapters), but the problem is with multiple conditions. I managed to make a method that generates the appropriate query based on which checkBoxes the user has checked (I displayed it in textBox4 so I know it is correct), but I don't know how to change the appropriate TableAdapters (that fill the datasets used to fill the report). I tried with:
KontrolorRadTableAdapter.Adapter.SelectCommand = new SqlCommand(textBox4.Text);
KontrolorRadTableAdapter.Fill(princMarpromTestDataSet.KontrolorRad);
reportViewer1.RefreshReport();
reportViewer1.Refresh();
But when I click the button that contains this code, nothing happens.
Do you have any ideas how to fix this? The only alternative, I can think of, is to make a TableAdapter query for every possible combination of conditions (there are 5 of them) but that is not practical, so can you suggest a more elegant solution?
Thanks
Loading
Sam HobbsPosted Feb 8, 2012, 5:21 PM
I suspect that the SQL you are using is incorrect. You use the text directly from the textBox4.Text; that looks suspicious to me. I would not do that but something else you can do is to use a try block around the code, to ensure that you catch the errors. It could be that the code is silently failing. You could determne that by using the debugger; put a breakpoint on the line that calls KontrolorRadTableAdapter.Fill and then single-step from there. You can do that right now without modifying your code.
Neven DraskovicPosted Feb 9, 2012, 6:08 AM
Anyway thanks for the previous answer.