gpt4 book ai didi

c# - 在 C# 中将 Dataset 元素转换为字符串数组

转载 作者:行者123 更新时间:2023-11-30 15:06:10 27 4
gpt4 key购买 nike

我正在尝试将数据集项转换为字符串并保存到数组中。但它给了我语法错误。请帮帮我。这在 VS 2005 和 C# 中

提前致谢!

string strdetailID[] = new string[4];
for(int i = 0; i < x ; i++)
{
strdetailID[i] = dsImages.Tables[0].Rows[i]["Ad_detailsID"].ToString();
}

最佳答案

List<string> strDetailIDList = new List<string>();    

foreach(DataRow row in dsImages.Tables[0].Rows)
{
strDetailIDList.Add(row["Ad_detailsID"].ToString());
}

string strDetailID[] = strDetailIDList.ToArray();

我用过 List<string>而不是 string数组,因为我认为动态添加元素会更容易,但如果你仍然想使用 string数组,你应该明白了。

关于c# - 在 C# 中将 Dataset 元素转换为字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8188866/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com