string extract from excel column is empty although there is text there RRS feed

  • Question

  • User-1641476077 posted

    Preview of the excel file

    OleDbDataAdapter da = new OleDbDataAdapter("Select * From [Sheet1$]", connExcel);
                                DataTable dt = new DataTable();
      foreach (DataRow dr in dt.Rows)
     insertStatement = "INSERT INTO Mapping (Description, BUCode, OracleCostCenter, Account) VALUES ('" + dr["Description"].ToString().Trim() + "','"
                                            + dr["BU Code"].ToString().Trim() + "','" + dr["Oracle"].ToString().Trim() + "','" + dr["Account"].ToString().Trim() + "')";
                                        sqlCommand = new SqlCommand(insertStatement, conn);

    the dr["Account"].ToString().Trim() is empty throughout the whole foreach loop

    Tuesday, March 4, 2014 10:23 PM

All replies

  • User1208776063 posted

    There are some blank values in the last column. But, if you want to treat the number as a sting, you need to add single quote(') while editing the excel file itself. Try modifying the first account number to '1234 and see if it works.

    Sunday, March 9, 2014 11:16 AM