如何从 tableAdapter 获取数据

how to get the data from the tableAdapter

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

我该怎么做?

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

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

newCityTable 有程序的结果。

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

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

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

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];

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

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

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

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