Home > DeveloperSection > Forums > How to Retrieving data from sql server and adding it to arraylist
Takeshi Okada
Takeshi Okada

Total Post:89

Points:629
Posted on    January-21-2015 10:20 PM

 MSSQL Server VB.Net  SQL Server 
Ratings:


 1 Reply(s)
 568  View(s)
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()



ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    January-21-2015 10:55 PM

While dr1.Read()

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

        arr10.Add(dr1(i).ToString)

    Next

End While


Don't want to miss updates? Please click the below button!

Follow MindStick