2
我在Visual Studio 2010中的Web服务上做了一个sql select语句。它只有一列,但有多行数据。如何用数据填充数据列表并返回它?如何用SQL填充ArrayList选择语句结果
[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;
}
}
你如何获取数据,使用什么?纯ado.net或一些orm也许?以下是您如何使用ArrayList:http://msdn.microsoft.com/en-us/library/system.collections.arraylist(v=vs.110).aspx –
从哪里返回数组列表? –
我会避免使用ArrayList,而是使用包含数据的强类型“List”。特别是因为所有的数据来自同一列,所以这应该是首选。 –
tvanfosson