自定义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);
                    }

posted @ 2014-08-04 11:12  画风  阅读(785)  评论(0编辑  收藏  举报