---
title: "How to Retrieving data from sql server and adding it to arraylist"  
description: "How to Retrieving data from sql server and adding it to arraylist"  
author: "Takeshi Okada"  
published: 2015-01-21  
updated: 2015-01-21  
canonical: https://www.mindstick.com/forum/12885/how-to-retrieving-data-from-sql-server-and-adding-it-to-arraylist  
category: "mssql server"  
tags: ["vb.net", "sql server"]  
reading_time: 1 minute  

---

# How to Retrieving data from sql server and adding it to arraylist

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [retrieve data](https://www.mindstick.com/forum/160347/how-do-you-retrieve-data-from-a-nosql-database-like-mongodb) from the [sql server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) and store it in an [arraylist](https://www.mindstick.com/articles/11973/arraylist-class-in-c-sharp) using [vb.net](https://www.mindstick.com/forum/426/sqlsever-2000-in-network-with-vb-dot-net-2008) but it is taking only one value and exiting while statement. I want to skip first 3 columns of the sql [server table](https://www.mindstick.com/forum/396/how-to-selecte-random-records-from-sql-server-table) and start [reading](https://www.mindstick.com/articles/126273/books-commonly-found-on-college-reading-lists) 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()
```

## Replies

### Reply by Anonymous User

While dr1.Read()

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

arr10.Add(dr1(i).ToString)

Next

End While


---

Original Source: https://www.mindstick.com/forum/12885/how-to-retrieving-data-from-sql-server-and-adding-it-to-arraylist

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
