inserting datareader objects into an arraylist... - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

inserting datareader objects into an arraylist...

neck_deepneck_deep Posts: 3Member
I have a question, How do i insert values from an sql server column into an arraylist? So far i have been trying the sqldatareader, but have problems.

I have made all the connections, and they are working fine. The problem i am having is storing the strings in the arraylist 1 by 1(most likely using the while loop), to be able to retrieve them later in the page. I am using vb.net/asp.net.some of the code is posted below:

dbconn.Open()
Dim myUserSql As String = "Select username from Customer"
Dim myCmd As New SqlCommand(myUserSql, dbconn)
Dim myreader As SqlClient.SqlDataReader
myreader = myCmd.ExecuteReader
While myreader.Read
myarr.Add(myreader.GetValues("username"))
End While
dbconn.close()


The purpose of the project is to store usernames in an arraylist, to be checked against the input from the user when they input into the appropriate field.

Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    : I have a question, How do i insert values from an sql server column into an arraylist? So far i have been trying the sqldatareader, but have problems.
    :
    : I have made all the connections, and they are working fine. The problem i am having is storing the strings in the arraylist 1 by 1(most likely using the while loop), to be able to retrieve them later in the page. I am using vb.net/asp.net.some of the code is posted below:
    :
    : dbconn.Open()
    : Dim myUserSql As String = "Select username from Customer"
    : Dim myCmd As New SqlCommand(myUserSql, dbconn)
    : Dim myreader As SqlClient.SqlDataReader
    : myreader = myCmd.ExecuteReader
    : While myreader.Read
    : myarr.Add(myreader.GetValues("username"))
    : End While
    : dbconn.close()
    :
    :
    : The purpose of the project is to store usernames in an arraylist, to be checked against the input from the user when they input into the appropriate field.
    :

    [code]
    dbconn.Open()
    Dim myUserSql As String = "Select username from Customer"
    Dim myCmd As New SqlCommand(myUserSql, dbconn)
    Dim myreader As SqlClient.SqlDataReader

    myreader = myCmd.ExecuteReader

    [b]
    Do While myreader.Read
    myarr.Add(myreader("username"))
    Loop
    [/b]

    [b]myreader.Close()[/b]
    dbconn.close()
    [/code]

    Through each Read, a datareader is merely a collection of columns populated with data from a specific row.

    Make sure you close your data-readers when your done as well.

  • neck_deepneck_deep Posts: 3Member
    : : I have a question, How do i insert values from an sql server column into an arraylist? So far i have been trying the sqldatareader, but have problems.
    : :
    : : I have made all the connections, and they are working fine. The problem i am having is storing the strings in the arraylist 1 by 1(most likely using the while loop), to be able to retrieve them later in the page. I am using vb.net/asp.net.some of the code is posted below:
    : :
    : : dbconn.Open()
    : : Dim myUserSql As String = "Select username from Customer"
    : : Dim myCmd As New SqlCommand(myUserSql, dbconn)
    : : Dim myreader As SqlClient.SqlDataReader
    : : myreader = myCmd.ExecuteReader
    : : While myreader.Read
    : : myarr.Add(myreader.GetValues("username"))
    : : End While
    : : dbconn.close()
    : :
    : :
    : : The purpose of the project is to store usernames in an arraylist, to be checked against the input from the user when they input into the appropriate field.
    : :
    :
    : [code]
    : dbconn.Open()
    : Dim myUserSql As String = "Select username from Customer"
    : Dim myCmd As New SqlCommand(myUserSql, dbconn)
    : Dim myreader As SqlClient.SqlDataReader
    :
    : myreader = myCmd.ExecuteReader
    :
    : [b]
    : Do While myreader.Read
    : myarr.Add(myreader("username"))
    : Loop
    : [/b]
    :
    : [b]myreader.Close()[/b]
    : dbconn.close()
    : [/code]
    :
    : Through each Read, a datareader is merely a collection of columns populated with data from a specific row.
    :
    : Make sure you close your data-readers when your done as well.
    :
    :


    Yeah, i knew it was something very basic that i was forgetting, thanks.

  • balajivallabalajivalla Posts: 1Member
    it dsnt matter if u knw r nt firt thank for his humble reply.. no one compeats here -helping each other out of kindness..

    i literally registered to site to give a reply..
Sign In or Register to comment.