I am importing an excel file using open XML, after importing i have two types of data showing in DOB column of excel , the first data type is double and second is in Datetime format.
How can i check data types of row containing datetime or double data so that i can perform conversion method?
protected DataSet CreateDataTableFromTextFile(string filePath)
{
//DataRow drClientCode = null;
DataRow dr = null;
CreateDataConfig dataConfig = null;
dtCustData = getdatatodatatable();
dtPanTable = new DataTable(); //Create first time only
dtPanTable = CreatePanTable();
VMGMFBridgeFactory.LookUpBridgeFactory lookUpBridgeFactory = null;
VMGMFBridge.ILookUpBridge iLookUpBridge = null;
DataTable lookUpData = null;
DBParameters processParameters = null;
DBParameters parameters = null;
int BSEMembId = 0;
if (ViewState["MemberCode"] != null && ViewState["MemberCode"] != "")
BSEMembId = Convert.ToInt32(ViewState["MemberCode"]);
else
BSEMembId = 0;
DataSet dsExcel = new DataSet();
try
{
if (dataLib == null)
{
dataConfig = new CreateDataConfig();
dataLib = dataConfig.GetDataConfigObject();
}
CreateDataLibObject();
lookUpBridgeFactory = new VMGMFBridgeFactory.LookUpBridgeFactory(dataLib);
iLookUpBridge = lookUpBridgeFactory.GetLookUpBridge();
//dtClinetCode.Columns.Add("CustomerID", (typeof(string)));
string[] lines = System.IO.File.ReadAllLines(filePath);
if (BSEMembId != 0)
{
string extension = Path.GetExtension(filePath);
using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
{
dsExcel = ImportExcelData(stream, extension, null);
DataTable dtimp = dsExcel.Tables[0];
if (dtimp.Columns.Contains("PAN_RP") && dtimp.Columns.Contains("INV_NAME") && dtimp.Columns.Contains("TAX_STATUS") && dtimp.Columns.Contains("DATA_SRC")&& dtimp.Columns.Contains("FR_NAME") && dtimp.Columns.Contains("SP_NAME") && dtimp.Columns.Contains("ADDR_TYPE"))
{
DataTable Currentdt= dsExcel.Tables[0];
Currentdt.Columns.Add("DOB_DATE",typeof(DateTime));
if (Currentdt.Columns["DOB"].DataType != typeof(DateTime))
{
for (int i = 0; i < Currentdt.Rows.Count; i++)
{
if(Currentdt.Rows[i]["dob"].ToString()=="" || Currentdt.Rows[i]["dob"].ToString() ==null )
{
}
else
{
if (Currentdt.Columns["DOB"].DataType != typeof(DateTime))
{
}
else
{
DateTime dobdate = DateTime.FromOADate(Convert.ToDouble(Currentdt.Rows[i]["dob"].ToString()));
// Currentdt.Columns.Add("DOB", typeof(DateTime));
Currentdt.Rows[i]["DOB_DATE"] = dobdate;
}
}
}
}
for (int i = 0; i < Currentdt.Rows.Count; i++)
{
if (Currentdt.Rows[i]["DOB_DATE"].ToString() == "")
{
Currentdt.Rows[i]["DOB_DATE"] = Currentdt.Rows[i]["DOB"];
}
}
DataTable dtClienCurrent = Currentdt;
for (int i = 0; i < dtClienCurrent.Rows.Count; i++)
{
if (!string.IsNullOrEmpty(dtClienCurrent.Rows[i]["PAN_RP"].ToString()))
{
processParameters = new DBParameters();
processParameters.Add(new DBParameter("PanNo", dtClienCurrent.Rows[i]["PAN_RP"].ToString()));
processParameters.Add(new DBParameter("JH1", ""));
processParameters.Add(new DBParameter("JH2", ""));
processParameters.Add(new DBParameter("IsGuardPAN", 0));
processParameters.Add(new DBParameter("Status", dtClienCurrent.Rows[i]["TAX_STATUS"].ToString()));
processParameters.Add(new DBParameter("FullName", dtClienCurrent.Rows[i]["INV_NAME"].ToString()));
lookUpData = iLookUpBridge.LookUpData(MFLookUpType.GetCustomerByPan, processParameters);
if (lookUpData.Rows.Count == 0)
{
dtClienCurrent.Rows[i].Delete();
}
else
{
}
}
}
dtClienCurrent.AcceptChanges();
}
else
{
lblMessage.Text = "Please Select Proper File Formate.";
dsExcel.Clear();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "mssg", "javascript:showMessage();", true);
}
}
}
else
{
lblMessage.Text = "Please Enter BSE login Credential in Application Configuration.";
// ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "closeAlertMsgAuto('Please Enter BSE Credential in Application Configuration.', 'auto');", true);
}
// dtCustomerDetail.AcceptChanges();
}
catch
{
throw;
}
finally
{
if (dataConfig != null)
{
dataConfig.DisposeDataConfigObject();
}
}
return dsExcel;
}