Groups | Blog | Home
all groups > dotnet ado.net > june 2006 >

dotnet ado.net : Number of characters in "SELECT * from ExcelSheetName"



Gary
6/30/2006 5:43:02 PM
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?

Robbe Morris [C# MVP]
6/30/2006 9:02:05 PM
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





[quoted text, click to view]

Gary
7/1/2006 12:52:01 PM
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

[quoted text, click to view]
Paul Clement
7/5/2006 11:38:29 AM
[quoted text, click to view]

¤ 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
~~~~
AddThis Social Bookmark Button