none
Run SQL-like queries on Data Table object ???? RRS feed

  • Question

  • Hello all,

     

    I need to be able to run SQL-like queries on a DataTable object and was just wondering is this possible.

     

    I have had a look at DataTable.Select()  and  DataView.rowFilter()  but I dont think these will suffice for what I need.

     

    Basically I need to run these types of SQL statement on a DataTable object:-

     

    SELECT DISTINCT CUST_REF

    FROM CUSTOMERS

     

    and also:-

     

    SELECT ORDER_NUM

    FROM CUSTOMERS

    GROUP BY ORDER_NUM

    HAVING (COUNT(ORDER_NUM) = 1)

     

    Is it possbile to run these types of queries on DataTable objects???

     

     

     

     

    Monday, January 28, 2008 9:48 AM

Answers

  • I do not think that helper classes cover everything and you would need to write your own functionality. For the update it should not be difficult. All you need to do is to use Select method to locate specific row(s) and then loop through array of returned DataRows and set new value(s) to the column(s).

     

    Tuesday, January 29, 2008 4:21 AM
    Moderator

All replies

  • There is no built-in functionality to do this, but there are several helper classes from Microsoft that provide such functionality. You could find code here

     

    http://support.microsoft.com/search/default.aspx?mode=a&query=helper&catalog=LCID%3D1033&1033comm=1&spid=6242

    Monday, January 28, 2008 11:24 AM
    Moderator
  • Thank you for the link.

     

    I just have another question.

     

    Can an UPDATE be done on a row in a datatable with a helper class or is there another way to do this ???

    I cant find a Helper class for UPDATE.

     

    I am trying to update certain row values when key field Cust_ref = @cust_ref

     

    Monday, January 28, 2008 11:55 AM
  • I do not think that helper classes cover everything and you would need to write your own functionality. For the update it should not be difficult. All you need to do is to use Select method to locate specific row(s) and then loop through array of returned DataRows and set new value(s) to the column(s).

     

    Tuesday, January 29, 2008 4:21 AM
    Moderator