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. General Programming
  3. Visual Basic
  4. VB.NET Windows Form Reading Excel dumping data into SQL server

VB.NET Windows Form Reading Excel dumping data into SQL server

Scheduled Pinned Locked Moved Visual Basic
databasehelpcsharpsql-server
2 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.
  • C Offline
    C Offline
    culbysl
    wrote on last edited by
    #1

    I situation is I need to pull the data from an Excel Spreadsheet and Insert it into a SQL Server DB. connecting excel via OleDb connection: strExCN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" which is connecting as it should. I hope someone can lend a hand on this. I can open the excel file and begins to read but when I come across an empty file I get a dbNull error. I have changed my select statement from "select * from [worksheet$]" to "select isnull(ColumnName, '') from [worksheet$]" and now am receiving and error saying OleDbException was unhandled Wrong number of arguments used with function in query expression 'IsNull('Column Name', '')'. Any help on this error would be wonderful. Thanks in advance culby sl

    D 1 Reply Last reply
    0
    • C culbysl

      I situation is I need to pull the data from an Excel Spreadsheet and Insert it into a SQL Server DB. connecting excel via OleDb connection: strExCN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" which is connecting as it should. I hope someone can lend a hand on this. I can open the excel file and begins to read but when I come across an empty file I get a dbNull error. I have changed my select statement from "select * from [worksheet$]" to "select isnull(ColumnName, '') from [worksheet$]" and now am receiving and error saying OleDbException was unhandled Wrong number of arguments used with function in query expression 'IsNull('Column Name', '')'. Any help on this error would be wonderful. Thanks in advance culby sl

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      culbysl wrote:

      I can open the excel file and begins to read but when I come across an empty file I get a dbNull error.

      When you come acrossed an empty Excel FILE?? Or Cell?? If it's an empty file, you can just capture the error in a Try/Catch block and move on:

      ' Setup connection stuff...
      ' Setup your loop, enumerating your files...
      Try
      ' Open the connection
      ' Execute the SELECT statement
      Catch ex As Exception
      ' Handle the emtpy file problem here...
      Finally
      If connection is not closed then
      Close connection
      End Try
       
      ' Loop around to process the next file...

      culbysl wrote:

      Wrong number of arguments used with function in query expression 'IsNull('Column Name', '')'.

      You can't use Excel functions in the SELECT statement because Excel is not doing the processing here. You should either stick with the * or specify the columns you're actually goint to use. Now, if your code is bombing try to use a DBNull value from a cell, then your code has to check to see if that value is DBNull before trying to use it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      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