如何从表适配器获取数据

本文关键字:获取 数据 适配器 | 更新日期: 2023-09-27 18:34:57

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

我该怎么做?

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

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

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();