Convert DataSet to List

后端 未结 11 2209
一整个雨季
一整个雨季 2020-12-04 08:39

Here is my c# code

Employee objEmp = new Employee();
List empList = new List();
foreach (DataRow dr in ds.Tables[0].Rows)
{
          


        
11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 09:16

                    DataSet ds = new DataSet();
                    ds = obj.getXmlData();// get the multiple table in dataset.
    
                    Employee objEmp = new Employee ();// create the object of class Employee 
                    List empList = new List();
                    int table = Convert.ToInt32(ds.Tables.Count);// count the number of table in dataset
                    for (int i = 1; i < table; i++)// set the table value in list one by one
                    {
                        foreach (DataRow dr in ds.Tables[i].Rows)
                        {
                            empList.Add(new Employee { Title1 = Convert.ToString(dr["Title"]), Hosting1 = Convert.ToString(dr["Hosting"]), Startdate1 = Convert.ToString(dr["Startdate"]), ExpDate1 = Convert.ToString(dr["ExpDate"]) });
                        }
                    }
                    dataGridView1.DataSource = empList;
    

    enter image description here

提交回复
热议问题