【问题标题】:how to get the data from the tableAdapter如何从 tableAdapter 中获取数据
【发布时间】:2016-02-17 16:10:23
【问题描述】:

我正在使用数据集和 Web 服务,在我的 Web 服务方法中,我调用并执行我在数据库中创建的过程,所以我的问题是 我有来自数据库的结果,但我不知道如何使用或调用数据本身。

我该怎么做?

我尝试搜索,但我得到的所有结果都是关于我不想使用的连接字符串。这是我第一次使用数据集和网络服务,所以可能我搜索的关键词有误。

这是我的代码,最后一行是我停下来不知道如何继续的地方。

newCityTable 有过程的结果。

 OrderDatasetTableAdapters.getCityNameTableAdapter newOrder = new OrderDatasetTableAdapters.getCityNameTableAdapter();
        newOrder.GetCityNameData();

        OrderDataset.getCityNameDataTable newCityTable;
        newCityTable = newOrder.GetCityNameData();

【问题讨论】:

    标签: c# asp.net web-services tableadapter


    【解决方案1】:

    终于找到了答案,在这里分享给大家。也许有人会觉得它有帮助。

    string city;
    // i here refers to the variable in a for loop. you can do whatever you want before like using loop, fetch a specific row or create an array..etc but this is the way to get the data that you want
    city = (string) newCityTable.Rows[i].ItemArray[0];
    

    【讨论】:

      【解决方案2】:

      您还可以执行以下操作(无需转换为项目数组),这可能更有效:

      city = newCityTable.Rows[i].Columns[0].ToString();
      

      或者一般来说,如果你有一个双 for 循环:

      city = newCityTable.Rows[i].Columns[j].ToString();
      

      【讨论】:

        猜你喜欢
        • 2011-04-11
        • 1970-01-01
        • 1970-01-01
        • 2017-10-26
        • 1970-01-01
        • 1970-01-01
        • 2014-05-22
        • 2018-07-14
        • 1970-01-01
        相关资源
        最近更新 更多