首页 > 代码库 > 自定义DataTable方法

自定义DataTable方法

                    //创建DataTable
                    DataTable dt = new DataTable();
                    dt.Columns.Add("EMP_NO", Type.GetType("System.String"));
                    dt.Columns.Add("BANK_NO", Type.GetType("System.String"));
                    dt.Columns.Add("PayRollAmount", Type.GetType("System.Int32"));

                    DataTable dtTemp = new DataTable();
                    dtTemp = ReadExcelToTable(path);
                   
                    for (int i = 1; i < dtTemp.Rows.Count; i++)
                    {
                        DataRow dr = dt.NewRow();
                        dr["EMP_NO"] = dtTemp.Rows[i][4].ToString();
                        dr["BANK_NO"] = dtTemp.Rows[i][10].ToString();
                        dr["PayRollAmount"] = Convert.ToInt32(dtTemp.Rows[i][9].ToString());
                        dt.Rows.Add(dr);
                    }