locked
TableAdapter sub query RRS feed

  • Question

  • Is it possible to write the following type of query in my dataset's tableadapter:

    @MyVar = (Select PhoneID from table where ID=@ID)

    Select TimeP From table where ID=@MyVar

    So basically what im trying to do is hold the value returned from the first part of the sub query inside @MyVar and then use that variable to select another column from the same table using the value obtained by the sub query - is this even possible?

    Thanks

    Thursday, March 21, 2013 9:03 PM

Answers

  • Try the following:

    SELECT timeP FROM TABLE WHERE ID = (SELECT PhoneID FROM TABLE WHERE ID = @ID)

    • Marked as answer by Youen Zen Thursday, April 4, 2013 8:50 AM
    Friday, March 22, 2013 11:24 PM
  • Probably you can. But you are than misusing a TableAdapter while there are more efficient ways. 

    A table adapter is to adapt a table (more particular a DataTable), not to create queries not related to a table. 

    Be aware that a TableAdapterManager can also get related tables. 

    If you want to handle things inside the tables. Than simply use the DataTable. You have all kind of methods for that, from simple VB methods accessing the tables to Linq to SQL. 

    But ask then a more precise question around that.

    By the way, I think you are better of by creating related tables in your database.


    Success
    Cor


    • Edited by Cor Ligthert Saturday, March 23, 2013 6:40 AM
    • Marked as answer by Youen Zen Thursday, April 4, 2013 8:50 AM
    Saturday, March 23, 2013 6:38 AM

All replies

  • Try the following:

    SELECT timeP FROM TABLE WHERE ID = (SELECT PhoneID FROM TABLE WHERE ID = @ID)

    • Marked as answer by Youen Zen Thursday, April 4, 2013 8:50 AM
    Friday, March 22, 2013 11:24 PM
  • Probably you can. But you are than misusing a TableAdapter while there are more efficient ways. 

    A table adapter is to adapt a table (more particular a DataTable), not to create queries not related to a table. 

    Be aware that a TableAdapterManager can also get related tables. 

    If you want to handle things inside the tables. Than simply use the DataTable. You have all kind of methods for that, from simple VB methods accessing the tables to Linq to SQL. 

    But ask then a more precise question around that.

    By the way, I think you are better of by creating related tables in your database.


    Success
    Cor


    • Edited by Cor Ligthert Saturday, March 23, 2013 6:40 AM
    • Marked as answer by Youen Zen Thursday, April 4, 2013 8:50 AM
    Saturday, March 23, 2013 6:38 AM