dataset to Listusing linq

前端 未结 6 645
别跟我提以往
别跟我提以往 2021-02-06 13:18

I have a DataSet and I want to convert the DataSet into List

T - type object

How convert my DataSet?

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-06 13:51

    A very simple approach that I use is following:

    List objList = new List();      
    foreach (DataRow _dataRow in dataSet.Tables[0].Rows)
                        {
                            Obj obj = new Obj();
                            obj.Col1 = Convert.ToInt32(_dataRow["Col1"]);
                            obj.Col2 = Convert.ToInt32(_dataRow["Col2"]);
                            obj.Col3 = Convert.ToString(_dataRow["Col3"]);
                            objList.Add(obj);
                        }
    

提交回复
热议问题