none
Copying values from select Query to arraylist RRS feed

  • Question

  •  

    Hi ,

    I am having a simple select query like this.
    select empID from tablename where <condition>;

     

    I want to copy all the empiD's that come out of the query and copy them to a arraylist, without iterating through the reader object and adding the contents in a loop.

     

    Is there a way to do this?

     

    Please let me know.

     

    Thanks,
    Praveen Raju

    Thursday, September 13, 2007 8:13 PM

Answers

  •  

    you can use sqldataadapter to fill the data into dataset or datatable, then you can manipulate the data from there. I dont know any way to fill an arraylist directly.
    Thursday, September 13, 2007 9:22 PM

All replies

  •  

    some code has to iterates through the resultset and adds them into an arraylist.

     

    do you mean to create a function that takes the query as input and returns arraylist with empiDs as output so you dont have to write that every time?

    Thursday, September 13, 2007 9:01 PM
  • Writing a function is fine.

     

    But i was wondering if there is a method or routine to add values from a query into a arraylist without looping which isthe regular method.

     

    If there are a large number of records then looping would take lot of resources isnt it?

     

    Let me know if there is a way..

    Thanks,

    Praveen Raju

    Thursday, September 13, 2007 9:06 PM
  •  

    you can use sqldataadapter to fill the data into dataset or datatable, then you can manipulate the data from there. I dont know any way to fill an arraylist directly.
    Thursday, September 13, 2007 9:22 PM
  • Hi Praveen,

     

    As far as I know, if you would like to load some data from a recordset, there should be existed a loop to do so. Based on my understanding, if there are a large number of records, a looping would take lot of resources. I recommend you to use a DataSet or a DataTable to save and access data.

     

    Hope this helps,

     

    Regards,

    Citizens on the earth

    Monday, September 17, 2007 6:14 AM