DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2008
    Posts
    13

    cannot create Excel file with field VARCHAR(8000)

    Couldn't find anywhere more appropriate to Excel, but it is kind of to do with Databases

    have read in a lot of places on the web that the max size for the varchar type is 8000 characters

    CREATE TABLE table1 (Field1 VARCHAR(8000))

    is a perfectly valid statement (assuming I got the above right)

    I have an application where I need to create an Excel Files using OleDB - the code follows:

    xconno = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & opath & ";Extended Properties=""Excel 8.0;HDR=YES;""")
    xconno.Open()
    sql = "CREATE TABLE Sheet2 (" & _
    "record_type INT, " & _
    "type INT, " & _
    "consignment_no VARCHAR(16), " & _
    "OrderNumber VARCHAR(16), " & _
    "order_number_2 VARCHAR(50), " & _
    "account_no VARCHAR(16), " & _
    "no_of_items INT, " & _
    "weight REAL, " & _
    "address_line_1 VARCHAR(50), " & _
    "address_line_2 VARCHAR(50), " & _
    "address_line_3 VARCHAR(50), " & _
    "address_line_4 VARCHAR(50), " & _
    "post_code VARCHAR(8), " & _
    "title_of_customer VARCHAR(8), " & _
    "forename_of_customer VARCHAR(50), " & _
    "initials VARCHAR(8), " & _
    "surname VARCHAR(50), " & _
    "telephone_number_of_customer VARCHAR(20), " & _
    "2nd_tele_number VARCHAR(20), " & _
    "3rd_tele_no VARCHAR(20), " & _
    "email_address VARCHAR(50), " & _
    "order_date VARCHAR(16), " & _
    "delivery_instructions VARCHAR(255), " & _
    "product_list VARCHAR(8000))" <<<<<<<<<<<<<<<
    xcmdo = New OleDbCommand(sql, xconno)
    xcmdo.ExecuteNonQuery()
    xconno.Close()

    The variable "opath" holds the filepath of the XLS file to be created. The code exist and is run in Visual Studio 2005.

    However, when I run the program within VS, I get an error on the line marked <<<<<<<<<<<<<

    ------------------------------------
    OleDbException was unhandled

    Size of field 'product_list' is too long.
    ------------------------------------

    In fact, if field product_list is declared any VARCHAR greater than VARCHAR(255), the above error occurs - this seems to fly in the face of waht everything else seems to say. The field 'product_list' must be greater than 255 characters, so the question is, how do I accomplish this?

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Welcome to DevX

    Run by itself in Enterprise Manager, this line of code ran just fine
    Code:
    CREATE TABLE table1 (Field1 VARCHAR(8000))
    In addition, also in Enterprise Manager, this ran just fine except for a Warning
    Code:
    CREATE TABLE Sheet2 (
    record_type INT, 
    type INT, 
    consignment_no VARCHAR(16), 
    OrderNumber VARCHAR(16),
    order_number_2 VARCHAR(50), 
    account_no VARCHAR(16), 
    no_of_items INT, 
    weight int, 
    address_line_1 VARCHAR(50), 
    address_line_2 VARCHAR(50), 
    address_line_3 VARCHAR(50), 
    address_line_4 VARCHAR(50), 
    post_code VARCHAR(8), 
    title_of_customer VARCHAR(8), 
    forename_of_customer VARCHAR(50), 
    initials VARCHAR(8), 
    surname VARCHAR(50), 
    telephone_number_of_customer VARCHAR(20), 
    Second_tele_number VARCHAR(20), 
    Third_tele_no VARCHAR(20), 
    email_address VARCHAR(50), 
    order_date VARCHAR(16), 
    delivery_instructions VARCHAR(255), 
    product_list VARCHAR(8000))
    The Warning given was this
    Quote Originally Posted by Enterprise Manager Warning
    Warning: The table 'Sheet2' has been created but its maximum row size (8882) exceeds the maximum number of bytes per row (8060). INSERT or UPDATE of a row in this table will fail if the resulting row length exceeds 8060 bytes.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Dec 2003
    Posts
    2,750
    If you're using Jet OLEDB then VARCHAR is limited to 255 characters. I seem to remember that Excel had a limitation with respect to column size. This may no longer be the case and if so I would try using MEMO or one of the corresponding data types (LONGTEXT, LONGCHAR, NOTE, NTEXT).
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    To me varchar says Oracle or SQL Server....it has nothing to do with Excel directly.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Dec 2003
    Posts
    2,750
    Jet SQL DDL (which is what you would use to create an Excel Worksheet in this instance) supports VARCHAR as well. It's a rather common keyword used amongst DBMS, if you want to refer to Excel or Access as a DBMS. ;-)
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    At the risk of sounding, at best picky, and at worst, snobbish, I do accept Access as a DBMS, but Excel is not a database...it is a spreadsheet...and, IMO, should not be used for anything other than that.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  7. #7
    Join Date
    Sep 2008
    Posts
    13
    Quote Originally Posted by Hack
    At the risk of sounding, at best picky, and at worst, snobbish, I do accept Access as a DBMS, but Excel is not a database...it is a spreadsheet...and, IMO, should not be used for anything other than that.
    I accept Access as only just a DB never mind a DBMS . I'm not using Excel as a database, the Excel file is just an output file for a report-sort of thing. Don't ask - customer requirement....

    Anyhoo, I used MEMO(8000) and Longvarchar(8000) where appropriate - as suggested above by pclement, thank you - and that works just fine.

    Now, as to whether I actually need 8000 characters.....

    Thanks to all for their input
    Last edited by leosuth; 09-13-2008 at 06:56 AM.

  8. #8
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Out of curiosity, which database you using; Oracle or SQL Server?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  9. #9
    Join Date
    Sep 2008
    Posts
    13
    I did say 'kind of to do with databases'

    Although this problem is to do with outputting data into an Excel file (the OLEDB kind of bringing in the database element - ie. handling of Sheets as though they were Tables), the source of the data could be anything, including a database.

    In this case, what I'm actually doing is inputting from a customer supplied XLS, doing some reformatting and consolidation of the data, and then outputting to another XLS to send back to customers (again, don't ask, they are paying for the service ). This is one 'tool' in a toolkit we use for various functions.

    Hopefully, if anyone else needs to do something similar from a database, well, here's the answer.

    Normally, I'd be using SQL Server

  10. #10
    Join Date
    Sep 2011
    Posts
    1

    Bstr

    I know this is an old post, but if anyone else runs into this, try changing the column type to Text or LongText the OleDbParameter type from OleDbType.Varchar to OleDbType.BSTR.

Similar Threads

  1. check if excel file is already open..Help!!
    By carrie09 in forum VB Classic
    Replies: 3
    Last Post: 09-04-2007, 11:17 AM
  2. Replies: 8
    Last Post: 01-23-2006, 03:27 PM
  3. wav file fade in out help
    By jase_dukerider in forum C++
    Replies: 2
    Last Post: 04-14-2005, 07:48 PM
  4. Can't create a PARADOX file and insert records using ODBC
    By Steve Oliver in forum VB Classic
    Replies: 0
    Last Post: 07-26-2002, 12:30 PM
  5. Ted, you're a prince!
    By Georgiana Trigg in forum VB Classic
    Replies: 0
    Last Post: 10-29-2000, 11:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links