Results 1 to 8 of 8

Thread: Excel 255 character limit for a cell? [Resolved]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Unhappy Excel 255 character limit for a cell? [Resolved]

    Hi.

    I'm transferring data from an Excel spreadsheet to a SQL Server DB via ADO. The code works as expected, but all of the data is not transferred over if a cell contains more than 255 characters - in other words, it is truncated. Does anyone know why this is happening? Better yet, a solution for the problem!

    Thanks,
    OneSource
    Last edited by OneSource; Aug 2nd, 2004 at 12:55 PM.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    At a guess the Sql server field is set to 255 max... either that or excel is as crap as I thought and its not letting you do it.

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Thanks Ecniv ....

    The SQL Server field has a size of 4000 characters, so that rules out option 1! That only leaves option 2: "excel is as crap as I thought and its not letting you do it."

    Thanks anyway.
    OneSource

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    How are you transfering it to SQL? Could it be that you may be
    using a variable of string type of default length 255? If you are
    using the variable, then just declare it of a greater length. I
    thought of this since you say that Excel has more than 255 chars
    in a cell. This would lead me to believe that Excel can handle the
    larger length. So it must be in your transfer code.

    Ps. Excel can handle the larger length. Just checked.
    Can you post some of your transfer code?

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    RobDog888 ...

    Thanks for your response.

    I was able to get around the problem by using a string array and a loop.
    VB Code:
    1. Public Sub Main()
    2.     Dim intLength As Integer
    3.     Dim strUpdateText() As String
    4.     Dim bytCtr As Byte
    5.  
    6.     ReDim strUpdateText(0)
    7.    
    8.     intLength = Len(Cells(1, 1).Text)
    9.    
    10.     Do
    11.         strUpdateText(UBound(strUpdateText)) = Mid(Cells(1, 1).Text, (bytCtr * 255) + 1, 255)
    12.         bytCtr = bytCtr + 1
    13.         ReDim Preserve strUpdateText(UBound(strUpdateText) + 1)
    14.         intLength = intLength - 255
    15.     Loop Until intLength < 0
    16.  
    17.     For bytCtr = 0 To UBound(strUpdateText) - 1
    18.         If bytCtr = 0 Then
    19.             'Update with strupdatetext(0)
    20.             strSQL = "UPDATE CultureProperties SET PropertyValue = '" & strUpdateText(bytCtr) & "' " & _
    21.                      "WHERE refID = " & CInt(Cells(intRowCtr, 1)) & " AND Culture = 'fr'"
    22.         Else
    23.             'Append with current text and strupdatetext(bytctr)
    24.             strSQL = "UPDATE CultureProperties SET PropertyValue = PropertyValue + '" & strUpdateText(bytCtr) & "' " & _
    25.                      "WHERE refID = " & CInt(Cells(intRowCtr, 1)) & " AND Culture = 'fr'"
    26.         End If
    27.         'Debug.Print strUpdateText(bytCtr)
    28.     Next
    29. End Sub
    I know it's cludgy, but it works. But I think you are right. I was using the default string type. When you refer to declaring the variable at greater length, do you mean something like this:
    VB Code:
    1. Dim strSQL$(5000)
    ?

    Anyway, I was trying to figure this out for a co-worker and saw the problem on her PC. When I just tried to transfer the data using a string variable declared in the conventional way (Dim strUpdateText As String) on my PC, it worked! I don't know why it would work on mine and not hers.

    Anyway, thanks again!

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Thanks, and kind of what I meant. The way your have it is as a
    string array. My way creates a string buffer of a length of 5000
    characters. Then use Trim to remove any trailing spaces that you
    don't need.

    VB Code:
    1. Dim strString As String * 5000
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    RobDog888 ...

    Thanks!

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No prob.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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