private void btnImport_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; DataTable dtMaterial = new DataTable(); DataTable sortedDT = new DataTable(); try { foreach (GridColumn column in grd_view1.VisibleColumns) { if (column.FieldName != string.Empty) { dtMaterial.Columns.Add(column.FieldName, column.ColumnType); } } for (int i = 0; i < grd_view1.DataRowCount; i++) { DataRow row = dtMaterial.NewRow(); foreach (GridColumn column in grd_view1.VisibleColumns) { row[column.FieldName] = grd_view1.GetRowCellValue(i, column); } dtMaterial.Rows.Add(row); } DataView dv = dtMaterial.DefaultView; dv.Sort = "EmpUnqID asc"; sortedDT = dv.ToTable(); using (SqlConnection con = new SqlConnection(Utils.Helper.constr)) { con.Open(); foreach (DataRow tdr in sortedDT.Rows) { string tEmpUnqID = tdr["EmpUnqID"].ToString(); if (string.IsNullOrEmpty(tEmpUnqID)) { tdr["Remarks"] = "EmpUnqID is blank..."; continue; } string tWrkGrp = tdr["WrkGrp"].ToString(); string tUnitCode = tdr["UnitCode"].ToString(); string tEmpName = tdr["EmpName"].ToString(); string tFatherName = tdr["FatherName"].ToString(); bool tSex = (tdr["Gender"].ToString() == "M" ? true : false); bool tActive = (tdr["Active"].ToString() == "Y" ? true : false); bool tPayrollFLG = (tdr["PayrollFlg"].ToString().Trim() == "Y"?true:false); bool tContractFlg = (tdr["ContractFlg"].ToString().Trim() == "Y"?true:false); bool tShiftType = (tdr["AutoShift"].ToString().Trim() == "Y"?true:false); bool tOTFLG = (tdr["OTFLG"].ToString().Trim() == "Y"?true:false); string tEmpCode = tdr["EmpCode"].ToString().Trim().ToUpper(); string tContCode = tdr["ContCode"].ToString().Trim().ToUpper(); string tWeekoff = tdr["WeekOff"].ToString().Trim().ToUpper(); string tEmpTypeCode = tdr["EmpTypeCode"].ToString().Trim(); string tCATCODE = tdr["CatCode"].ToString().Trim().ToUpper(); string tDeptcode = tdr["DeptCode"].ToString().Trim().ToUpper(); string tStatCode = tdr["StatCode"].ToString().Trim().ToUpper(); string tDesgCode = tdr["DesgCode"].ToString().Trim().ToUpper(); string tGradeCode = tdr["GradCode"].ToString().Trim().ToUpper(); string tMessGrpCode = tdr["MessGrpCode"].ToString().Trim().ToUpper(); string tMessCode = tdr["MessCode"].ToString().Trim().ToUpper(); string tOldEmpCode = tdr["OldEmpCode"].ToString().Trim().ToUpper(); string tSAPID = tdr["SAPID"].ToString().Trim().ToUpper(); string tCostCode = tdr["CostCode"].ToString().Trim().ToUpper(); string tAdharNo = tdr["AdharNo"].ToString().Trim().ToUpper(); string tShiftCode = tdr["ShiftCode"].ToString().Trim().ToUpper(); double tbasic = 0; double tsplALL = 0; double tbaALL = 0; try { double.TryParse(tdr["Basic"].ToString(), out tbasic); } catch (Exception ex) {} try { double.TryParse(tdr["SPLALL"].ToString(), out tsplALL); } catch (Exception ex) {} try { double.TryParse(tdr["BAALL"].ToString(), out tbaALL); } catch (Exception ex) { } DateTime?tValidFrom = new DateTime?(); DateTime?tValidTo = new DateTime?(); try { tValidFrom = Convert.ToDateTime(tdr["ValidFrom"]); tValidTo = Convert.ToDateTime(tdr["ValidTo"]); } catch (Exception ex) { } DateTime tBirthDt = Convert.ToDateTime(tdr["BirthDt"]); DateTime tJoinDt = Convert.ToDateTime(tdr["JoinDt"]); clsEmp emp = new clsEmp(); string err = string.Empty; bool iscreated = emp.CreateEmployee(tEmpUnqID, tWrkGrp, tUnitCode, tEmpName, tFatherName, tSex, tActive, tBirthDt, tJoinDt, tWeekoff, tPayrollFLG, tContractFlg, tShiftType, tOTFLG, false, false, tEmpCode, tContCode, tEmpTypeCode, tCATCODE, tDeptcode, tStatCode, tDesgCode, tGradeCode, tMessGrpCode, tMessCode, tOldEmpCode, tSAPID, tCostCode, tAdharNo, tValidFrom, tValidTo, tbasic, tsplALL, tbaALL, out err); if (string.IsNullOrEmpty(err)) { tdr["Remarks"] = "Employee Created..."; } else { tdr["Remarks"] = err; } } con.Close(); } Cursor.Current = Cursors.Default; MessageBox.Show("file uploaded Successfully, please check the remarks for indivisual record status...", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } DataSet ds = new DataSet(); ds.Tables.Add(sortedDT); grd_view.DataSource = ds; grd_view.DataMember = ds.Tables[0].TableName; grd_view.Refresh(); Cursor.Current = Cursors.Default; }