views:

294

answers:

1

Can a DevExpress XtraGrid be filled using a a Dynamic SELECT statement string?

i.e. SELECT * FROM Employee
or
SELECT * FROM Dependents

To fill our XtraGrids currently, we use a ORM that creates entities. To do this it takes a lot of steps and time. What is driving me to ask this question is we do a lot of client aquistions where we get hundreds of files. I do not want to create entities for all of these then have to create an XtraGrid for each entity. Ideally if I can just feed it a SELECT statement and the XtraGrid could render it then I could use the XtraGrid very nice data minipulation features (Filter, Group By, etc).

If you have any other ideas or suggestions please do not hesitate to post them.

Revised:
Per Brendon's responce below to create a static method that returns a DataTable.
Here is a link to a page that actually does that. http://msmvps.com/blogs/deborahk/archive/2009/07/07/dal-retrieve-a-datatable-using-a-sql-statement.aspx

+1  A: 

The XtraGrid doesn't have any built-in mechanisms to create a data source from a SQL statement. For me, the easiest way to accomplish this is to simply create a static method that builds and returns a DataTable/DataSet from a SQL statement. I can then set the XtraGrid's data source to the results of this method.

Brendon
Thanks for the responce. Here is a link to code that returns a DataTable. http://msmvps.com/blogs/deborahk/archive/2009/07/07/dal-retrieve-a-datatable-using-a-sql-statement.aspx I have not been able to work on passing this to the XtraGrid yet but at least this looks like a good starting place. Thanks again!
Gerhard Weiss
That's very similar to what I use. If you are NOT working in a master-detail scenario, you'll simply need to assign this DataTable to the XtraGrid's DataSource property. If you need to use a master-detail scenario, you'll have to use a DataSet.
Brendon