C# DataTable转数组

string strsql = $"select name from 表名";
DataTable dt = base.GetDataTable(strsql);
string[] result = new string[dt.Rows.Count];
for (int i = 0; i < result.Length; i++)
{
    foreach (DataColumn item in dt.Columns)
    {
        result[i] = dt.Rows[i][item].ToString();
    }
}
return result;

or

string strsql = $"select * from 表名";
DataTable dt = base.GetDataTable(strsql);
string[] result = new string[dt.Rows.Count];
for (int i = 0; i < result.Length; i++)
{
    foreach (DataColumn item in dt.Columns)
    {
        result[i] = dt.Rows[i]["name"].ToString();
    }
}
return result;
© 版权声明
THE END
喜欢就支持一下吧
点赞5赞赏
分享
评论 抢沙发

请登录后发表评论