如何在数据表转换价值为C#中的字符串数组 [英] How to Convert the value in DataTable into a string array in c#
问题描述
我有一个包含一个行的DataTable。我想这个数据表中的值转换为字符串数组,这样我可以通过字符串数组索引
为例访问该数据表的列值,如果我的数据表如下:
|名称|地址|年龄|
-------------------------------
|吉姆|美国| 23 |
我想在数据表中的值保存到我的字符串数组,这样的 MyStringArray [1 ] 会给我的价值USA。
在前进
非常简单:
VAR stringArr = dataTable.Rows [0] .ItemArray.Select(X => x.ToString())ToArray的();
其中的 DataRow.ItemArray
属性是一个包含该行的值数据的每个列对象的数组表。
I have a DataTable that contains a single row. I want to convert this DataTable values into a string array such that i can access the column values of that DataTable through the string array index For example, if my DataTable is as follows
| Name | Address | Age |
-------------------------------
| jim | USA | 23 |
I want to store the values in that Datatable into my string array such that MyStringArray[1] will give me the value USA.
Thanks in Advance
Very easy:
var stringArr = dataTable.Rows[0].ItemArray.Select(x => x.ToString()).ToArray();
Where DataRow.ItemArray
property is an array of objects containing the values of the row for each columns of the data table.
这篇关于如何在数据表转换价值为C#中的字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!