2017-10-07 125 views
-1

不能隱式轉換類型system.collections.generic.List 到System.Data.DataTable如何列表對象轉換爲DataTable對象

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

DataTable dt = selectedCustomer; 

這怎麼上述錯誤消息來解決?

+1

使用'MoreLinq'這樣的回答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

相關問題