Results 1 to 5 of 5

Thread: Import date

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    19

    Import date

    I am trying to import excel data into a sql table useing ADO in VB.
    Everything works fine but, there are two fields in the excel file that come as date and currency. My table in sql has datetime and money data type for these fields. When try to append the data

    by this method
    rsSql.Fields(0)=rsExcel.Fields(0)
    '
    '
    '
    '
    '
    rsSql.Fields(10)=rsExcel.Fields(10)


    all of the fields are updated but these two fields the date and currency are not updated can some one help me out with this?

  2. #2
    Addicted Member Mandelbrot's Avatar
    Join Date
    Aug 2001
    Location
    Work, as usual!!
    Posts
    241
    I'm not totally sure here, but have you tried changing formats of the imported fields to Doubles? Most SQL style databases interpret money and time as Double precision numbers. Try using:

    rsSql.Fields(0)=CDbl(rsExcel.Fields(0))

    See how you get on!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    19
    Thanks,
    But the rsExcel.Fields(0) doesn't even populated with any values, when I go in debug mode there is null value. Also
    the date is formatted as custom mm"/"dd"/"yyyy in excel file......
    any thoughts???

  4. #4
    Addicted Member Mandelbrot's Avatar
    Join Date
    Aug 2001
    Location
    Work, as usual!!
    Posts
    241
    Hmmm...

    I'm not sure about why you're not getting anything back, but the custom format doesn't matter. (You'll see what I mean if you change the format for a date to:

    #,##0.0000
    Last edited by Mandelbrot; Oct 12th, 2001 at 12:38 AM.

  5. #5
    Lively Member
    Join Date
    Oct 2000
    Location
    Leicestershire; ENGLAND
    Posts
    71
    Dates are stored in Excel as a number since a specified date. The value that you will be transferring is probably just this number rather than the date itself.
    If you use a date in SQL Server, the SQL string would normally be something like "Update MyTable Set MyDate=#12/10/2001#".
    You will probably have to read the date into your program and then format it correctly for SQL Server.
    In the mean time, have you thought of using the Excel object in your program to access the spreadsheet data instead. Then you can read the data as a date!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width