2017-10-07 8 views
-1

が暗黙のうちにこのエラーメッセージは、上記の解決することができますどのように DataTableオブジェクトにリストオブジェクトを変換する方法

List<string> selectedCustomer = new List<string>(); 
selectedCustomer.Add(CustomerID); 
selectedCustomer.Add(FirstName); 
selectedCustomer.Add(LastName); 

DataTable dt = selectedCustomer; 

たSystem.Data.DataTable

に型system.collections.generic.List を変換することはできませんか?

+1

この回答のように 'MoreLin'を使用してください。https://stackoverflow.com/a/42550827/2946329 –

答えて

0
static DataTable GetTable() 
{ 
    // Here we create a DataTable with four columns. 
    DataTable table = new DataTable(); 
    table.Columns.Add("Dosage", typeof(int)); 
    table.Columns.Add("Drug", typeof(string)); 
    table.Columns.Add("Patient", typeof(string)); 
    table.Columns.Add("Date", typeof(DateTime)); 

    // Here we add five DataRows. 
    table.Rows.Add(25, "Indocin", "David", DateTime.Now); 
    table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); 
    table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); 
    table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); 
    table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); 
    return table; 
} 

HEPSİALINTIDIR!

+0

英語で質問に答えてください。 – Schwesi

関連する問題