简体   繁体   中英

how to get dataTable from arraylist in which dataTable is stored?

I have an ArrayList , it has a string at 0th position and DataTable at 1st position is it possible to get DataTable back?

ArrayList dataModel = new ArrayList();
DataTable dt = new DataTable();
dt.Columns.Add("A");
dt.Columns.Add("B");
dt.Columns.Add("C");
dt.Rows.Add("1","Rahul","Vapi");
dt.Rows.Add("2", "Yash", "Vapi");
dt.Rows.Add("3", "Dinesh", "vapi");

dataModel.Add("this is working for me");
dataModel.Add(dt);

I am getting this error :

Cannot implicitly convert type 'object' to 'System.Data.DataTable'. An explicit conversion exists (are you missing a cast?)

(are you missing a cast?)

Yes.

DataTable dt = (DataTable) dataModel[1];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM