DataView类的实例本身就可以当数组使用:
//DataView DV;
DataRowView DRV=DV[行号];
如果要导出某列数据可这样做:
//DataView DV;int I;
object[] OS = new object[DV.Count];
for (I = 0; I < OS.Length; I++)
{
OS[I] = DV[I][列号或列名称];
}
vb.net例子:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DV As DataView : Dim I As Int16
DV = New DataView(New DataTable("新表"))
DV.Table.Columns.Add("列1")
DV.AddNew() : DV.AddNew() : DV.AddNew() : DV.AddNew()
DV.Item(0)(0) = "a"
DV.Item(1)(0) = 56
DV.Item(2)(0) = 8.56
DV.Item(3)(0) = "fdg"
Dim OS(DV.Count - 1) As Object
For I = 0 To OS.Length - 1
'OS(I) = DV(I)(列号或列名称)
OS(I) = DV(I)(0)
Next I
End Sub
End Class
Dim rowsCount As Integer = DataGridView1.Rows.Count '统计行数
Dim colsCount As Integer = DataGridView1.Columns.Count '统计列数
Dim arrReturn As New String("100", 100)
arrDate(100, 100) = Nothing '把数组置为空
Dim x, y As Integer '用于控制数组的上下限
For x = 0 To rowsCount - 1
For y = 0 To colsCount - 1
arrDate(x, y) = Me.DataGridView1.Rows(x).Cells(y).FormattedValue.ToString
If y = colsCount - 1 Then
arrDate(x, y) = Me.DataGridView1.Rows(x).Cells(y).FormattedValue.ToString & Chr(13) + Chr(10)
End If
Next
Next