2017-10-07 4 views
-1

암시 적 타입 system.collections.generic.List 이 오류 메시지가 위에서 해결 될 수있는 방법 어떻게 DataTable 개체에 목록 개체를 변환하는

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

DataTable dt = selectedCustomer; 

을 System.Data.DataTable로 변환 할 수없는 이유는 무엇입니까?

+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