DataTable

关于c#中将Datatable 中的数据进行循环到 list对象中

    List<SinHotSpotModel> SinHotSpotList = new List<SinHotSpotModel>();
                string SqlHost = string.Format("select * from SinHotspot where TaskId = '{0}'",TaskId).ToString();
                DataTable SelectHostTable = ModeService.SinDBHelper.SelectAll(SqlHost);

                    //for (int i = 0; i < SelectHostTable.Rows.Count; i++)
                    //{
                    
                    //    SinHotSpotList.Add(new SinHotSpotModel { TaskId = SelectHostTable.Rows[i]["Id"].ToString() });
                    //}
                    foreach (DataRow dr in SelectHostTable.Rows)
                    {
                        SinHotSpotList.Add(new SinHotSpotModel { TaskId = dr["Id"].ToString() });
                    } 
此为将datatable 查出来的数据进行循环到list 集合中的2中方法

猜你喜欢

转载自blog.csdn.net/milijiangjun/article/details/79975002