Advertisement

03.04.2008 at 01:17PM PST, ID: 23214096
[x]
Attachment Details

Using ADO.Net to retrieve data from Excel 2007 - Cannot import more than 255 columns

Asked by Mehawitchi in .NET, Miscellaneous Programming, .NET Framework 2.0

Tags: Microsoft, ADO.Net, 2, Maximum columns in Dataset/Table

Hello there,

I have an application in VB.Net in which I import data from Excel to SQL server database.

I'm trying to retrieve a table in Excel 2007 worksheet, which has more than 255 columns, using Ado.net 2

The problem is the dataset will always import a maximum of 255 columns. I've posted this problem recently and got a reply from one of the experts saying that Ado.net tables can handle even 10,000 columns and that the problem might be in MDAC, being an older version.

I've checked my system and found that I have the latest MDAC version (2.8).

I'm attaching here the code I'm using in the hope that I can get some advice as to how to overcome this limitation in Ado.net

The problem is clearly in the    da.Fill(dsXLData, "Ratings") command, as I have checked the number of filled columns in the dataset and it was 255, whereas my worksheet has around 280 (Excel 2007)

Appreciate any help on the aboveStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
'The connection string.
            Dim xlCon As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                                "Data Source=" & lblImportFile.Text & _
                                ";Extended Properties=""Excel 12.0;HDR=YES"""
 
 
            Try
 
                    'Excel "SELECT" statement
                    XlsSQL = "Select * from [Sheet1$]
 
                    'Declare and instantiate the connection object.
                    Dim con As New OleDbConnection(xlCon)
 
                    'Declare and instantiate the command object.
                    Dim com As New OleDbCommand()
 
                    'Declare and instantiate a DataAdapter which fill the dataset with data.
                    Dim da As New OleDbDataAdapter
 
                    'Add values to the command object's properties.
                    With com
                        .Connection = con
                        .CommandType = CommandType.Text
                        .CommandText = XlsSQL
                    End With
 
                    With da
                        .AcceptChangesDuringFill = False
                        .SelectCommand = com
                        'Add data to the dataset.
                        .Fill(dsXLData, "Ratings")
                    End With
 
                    MsgBox(dsXLData.Tables("Ratings").Rows.Count & " Rows")
                    MsgBox(dsXLData.Tables("Ratings").Columns.Count & " Clmns")
                    da.Dispose()
                    con.Dispose()
[+][-]03.04.2008 at 02:47PM PST, ID: 21045966

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.04.2008 at 03:31PM PST, ID: 21046312

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.04.2008 at 04:03PM PST, ID: 21046553

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, Miscellaneous Programming, .NET Framework 2.0
Tags: Microsoft, ADO.Net, 2, Maximum columns in Dataset/Table
Sign Up Now!
Solution Provided By: dimante
Participating Experts: 1
Solution Grade: B
 
 
[+][-]03.05.2008 at 07:08AM PST, ID: 21050901

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628