I am doing an sql select statement on my web service in Visual Studio 2010. It is only from a column but there are multiple rows of data. How do I populate an arraylist with the data and return it?
[WebMethod]
public List<String> getAccType(string bankId)
{
myConnection.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT TypeName FROM AccType where BankID = '" + bankId + "'", myConnection);
myReader = myCommand.ExecuteReader();
List<String> AccType = new List<string>();
while (myReader.Read())
{
string iAccType = myReader["TypeName"].ToString();
AccType.Add(iAccType);
}
return AccType;
}
}
List<T>containing the data. Especially since all the data is coming from the same column this should be preferred.