Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Excel Import Problem

Excel Import Problem

Scheduled Pinned Locked Moved ASP.NET
windows-adminxmlhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adkalavadia
    wrote on last edited by
    #1

    Hi, See my code for importing data from excel sheet.I have problem with importing data which contains in one column all record in digit except one is in charecters. The row containing charecters in that perticular column is not imported. string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathName + @"\" + fileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\""; OleDbConnection ExcelConnection = new OleDbConnection(excelConnectionString); OleDbCommand ExcelCommand = new OleDbCommand(); ExcelCommand.Connection = ExcelConnection; OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter(ExcelCommand); ExcelConnection.Open(); DataTable ExcelSheets = ExcelConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,null); string SpreadSheetName = "[" + ExcelSheets.Rows[workSheetNumber]["TABLE_NAME"].ToString() + "]"; ExcelCommand.CommandText = @"SELECT * FROM " + SpreadSheetName; ExcelAdapter.Fill(ExcelDataSet); In my "Password" colomn all record contains digits but one record contains charecters. At a time of debuging, i have found record contains NULL value. I have done lots of googling for this problem but still face this problem. My registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel key ImportMixedTypes=Text.

    !- F - R - I - E - N - D - S -!

    T 1 Reply Last reply
    0
    • A adkalavadia

      Hi, See my code for importing data from excel sheet.I have problem with importing data which contains in one column all record in digit except one is in charecters. The row containing charecters in that perticular column is not imported. string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathName + @"\" + fileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\""; OleDbConnection ExcelConnection = new OleDbConnection(excelConnectionString); OleDbCommand ExcelCommand = new OleDbCommand(); ExcelCommand.Connection = ExcelConnection; OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter(ExcelCommand); ExcelConnection.Open(); DataTable ExcelSheets = ExcelConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,null); string SpreadSheetName = "[" + ExcelSheets.Rows[workSheetNumber]["TABLE_NAME"].ToString() + "]"; ExcelCommand.CommandText = @"SELECT * FROM " + SpreadSheetName; ExcelAdapter.Fill(ExcelDataSet); In my "Password" colomn all record contains digits but one record contains charecters. At a time of debuging, i have found record contains NULL value. I have done lots of googling for this problem but still face this problem. My registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel key ImportMixedTypes=Text.

      !- F - R - I - E - N - D - S -!

      T Offline
      T Offline
      T M Gray
      wrote on last edited by
      #2

      The excel driver makes an assumption about the data type of each column based on the data in the first 8 rows. If you mix data types in the same column you need to format your excel sheet properly to get the data type set correctly. Related MS KB article[^]

      A 1 Reply Last reply
      0
      • T T M Gray

        The excel driver makes an assumption about the data type of each column based on the data in the first 8 rows. If you mix data types in the same column you need to format your excel sheet properly to get the data type set correctly. Related MS KB article[^]

        A Offline
        A Offline
        adkalavadia
        wrote on last edited by
        #3

        Actually my client is upload excel sheet. I can't format cells in every sheet. is it any way to format excel sheet column? or any other Extended Property is there?

        !- F - R - I - E - N - D - S -!

        T 1 Reply Last reply
        0
        • A adkalavadia

          Actually my client is upload excel sheet. I can't format cells in every sheet. is it any way to format excel sheet column? or any other Extended Property is there?

          !- F - R - I - E - N - D - S -!

          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          The second result of a google search[^] for "c# excel format column" (without the quotes) gives you the answer.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups