2011-02-23 140 views
-1
DataTable dt = new DataTable(); 
    string str; 
    string[] s = Array.ConvertAll<DataRow, string>(dt.Select(), delegate(DataRow row) 
    { 
     return (string)row[""]; 
    }); 
    str = String.Join(",", s); 
+2

問題是這麼好措辭,我無語... – Mehrdad 2011-02-23 06:48:02

回答

0

你在尋找類似如下:

Dim dt As DataTable = New DataTable() 
    Dim str As String 
    Dim s As String() = Array.ConvertAll(Of DataRow, String)(dt.Select(), Function(row As DataRow) DirectCast(row(""), String)) 
    str = String.Join(",", s) 

VB 8.0 (.Net 2.0)情況下,它不支持匿名方法。要解決的是,使用下面的代碼:

Dim dt As DataTable = New DataTable() 
    Dim str As String 
    Dim s As String() = Array.ConvertAll(Of DataRow, String)(dt.Select(), AddressOf ConvertRowToString) 
    str = String.Join(",", s) 

ConvertRowToString功能:

Function ConvertRowToString(ByVal row As DataRow) As String 
     Return DirectCast(row(""), String) 
    End Function 
+0

它給語法錯誤「的表達研究例外」的功能關鍵字 – Ramamoorthy 2011-02-23 06:58:29

+0

你使用的是什麼版本的VB/.Net Framework? – decyclone 2011-02-23 06:59:46

+0

你爲什麼使用'CType'? – 2011-02-23 07:05:23