Home All Groups Group Topic Archive Search About

Number of characters in "SELECT * from ExcelSheetName"

Author
1 Jul 2006 12:43 AM
Gary
I've got some perfectly fine code that works well for importing data from an
Excel spreadsheet into a .NET DataTable, except I discovered today that it's
cutting off any cell that contains more than 250 characters at that
250-character limit.  Is that just the way it is, or is there some way around
it?

Thanks!

Author
1 Jul 2006 1:02 AM
Robbe Morris [C# MVP]
Are you sure your DataTable schema is correct?

--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp





Show quote
"Gary" <G***@discussions.microsoft.com> wrote in message
news:6413ABD8-8CE6-4F5F-9B21-240619C5B0E3@microsoft.com...
> I've got some perfectly fine code that works well for importing data from
> an
> Excel spreadsheet into a .NET DataTable, except I discovered today that
> it's
> cutting off any cell that contains more than 250 characters at that
> 250-character limit.  Is that just the way it is, or is there some way
> around
> it?
>
> Thanks!
Author
1 Jul 2006 7:52 PM
Gary
I think so.  Everything works fine except that cells with more than 250
characters are truncated to 250 characters.  Here's the actual function code
(not mine, but pulled from somewhere on the web).  All variables that you
don't see declared are declared globally in the class.

Public Function GetDataTable(ByVal strSheetName As String) As DataTable

Dim strLocalSheetName, strRange, strSqlCommand As String

dtblExcel = New DataTable(strSheetName)
Try
  If (strSheetName.IndexOf("|") > 0) Then
    strLocalSheetName = strSheetName.Substring(0, strSheetName.IndexOf("|"))
    strRange = strSheetName.Substring(strSheetName.IndexOf("|") & 1)
    strSqlCommand = "SELECT * FROM [" & strLocalSheetName & "$" & strRange &
"]"
  Else
    strSqlCommand = "SELECT * FROM [" & strSheetName & "$]"
  End If

  dadExcel = New OleDbDataAdapter(strSqlCommand, conDBConnection)
  dadExcel.FillSchema(dtblExcel, SchemaType.Source)
  dadExcel.Fill(dtblExcel)
  conDBConnection.Close()

  Return dtblExcel
Catch
  Return Nothing
End Try

End Function

Show quote
"Robbe Morris [C# MVP]" wrote:

> Are you sure your DataTable schema is correct?
>
> --
> Robbe Morris - 2004-2006 Microsoft MVP C#
> Earn money answering .NET questions
> http://www.eggheadcafe.com/forums/merit.asp
>
>
>
>
>
> "Gary" <G***@discussions.microsoft.com> wrote in message
> news:6413ABD8-8CE6-4F5F-9B21-240619C5B0E3@microsoft.com...
> > I've got some perfectly fine code that works well for importing data from
> > an
> > Excel spreadsheet into a .NET DataTable, except I discovered today that
> > it's
> > cutting off any cell that contains more than 250 characters at that
> > 250-character limit.  Is that just the way it is, or is there some way
> > around
> > it?
> >
> > Thanks!
>
>
>
Author
5 Jul 2006 4:38 PM
Paul Clement
On Fri, 30 Jun 2006 17:43:02 -0700, Gary <G***@discussions.microsoft.com> wrote:

¤ I've got some perfectly fine code that works well for importing data from an
¤ Excel spreadsheet into a .NET DataTable, except I discovered today that it's
¤ cutting off any cell that contains more than 250 characters at that
¤ 250-character limit.  Is that just the way it is, or is there some way around
¤ it?

It's probably truncating at 255. Try adding the IMEX argument to your connection string.

        ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=e:\My Documents\Book20.xls;Extended Properties=""Excel 8.0;HDR=NO;IMEX=1"""


Paul
~~~~
Microsoft MVP (Visual Basic)

AddThis Social Bookmark Button