inserting datareader objects into an arraylist...

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

  • : 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.

  • : : 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.

  • 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.

Howdy, Stranger!

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

Categories