将一个函数中的多个数据传递给C#中的标签

时间:2014-04-27 05:36:42

标签: c# asp.net visual-studio-2010 amazon-web-services

我有一个检索多行数据的函数,我想在标签中显示它们。我的功能如下所示。

public static string GetItemByQuery(IAmazonSimpleDB simpleDBClient, string domainName)
    {

        SelectResponse response = simpleDBClient.Select(new SelectRequest()
        {
            SelectExpression = "Select * from " + domainName
        });
        String res = domainName + " has: ";

        foreach (Item item in response.Items)
        {
            res = item.Name + ": ";
            foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attributes)
            {
                res += "{" + attribute.Name + ", " + attribute.Value + "}, ";
            }
            res = res.Remove(res.Length - 2);


        }

        return res;
    }

到目前为止,我只能返回一个字符串,它是检索数据的最后一行。如何检索所有记录?我尝试arraylist,但似乎AWS Web应用程序不允许我使用arraylist。任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

将其作为Enumerable,

返回
List<String> Results ;  

你的方法是

public static List<String> GetItemByQuery(IAmazonSimpleDB simpleDBClient, string domainName)
    {
       List<String> Results = null;
        SelectResponse response = simpleDBClient.Select(new SelectRequest()
        {
            SelectExpression = "Select * from " + domainName
        });
        String res = domainName + " has: ";

        foreach (Item item in response.Items)
        {
            Results = new List<String>();
            res = item.Name + ": ";
            foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attributes)
            {
                res += "{" + attribute.Name + ", " + attribute.Value + "}, ";
            }
            res = res.Remove(res.Length - 2);
            Results.Add(res);
        }

        return Results;
    }