HOW TO RETRIEVING DATA FROM SQL SERVER AND ADDING IT TO ARRAYLIST

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
 908  View(s)
Ratings:
Rate this:

I am trying to retrieve data from the sql server and store it in an arraylist using vb.net but it is taking only one value and exiting while statement. I want to skip first 3 columns of the sql server table and start reading from 4th column.

    Dim arr10 As New ArrayList

    Dim i3 As Integer

    i3 = 3

    con.ConnectionString = "Data Source='" + System.Net.Dns.GetHostName + "'; Initial Catalog=hrmdb; Integrated Security=True"

    con.Open()

    Dim q1 As String = "SELECT * from empsal where emplycode='" + s2.ToString + "'"

    Dim cm1 = New SqlCommand(q1, con)

    Dim dr1 As SqlDataReader = cm1.ExecuteReader()

    While dr1.Read()

        arr10.Add(dr1(i3).ToString)

        i3 = i3 + 1

    End While

    dr1.Close()

    con.Close()

  1. ezra heywood

    Post:145

    Points:1019
    Re: How to Retrieving data from sql server and adding it to arraylist

    While dr1.Read()

        For i As Integer = 3 to CType(dr1, IDataRecord).FieldCount - 1

            arr10.Add(dr1(i).ToString)

        Next

    End While

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!