Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Weird Excel import into a dataset
Message
From
08/03/2007 20:00:41
John Baird
Coatesville, Pennsylvania, United States
 
 
To
08/03/2007 16:01:26
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01202088
Message ID:
01202162
Views:
13
Here is a snippet of working code that works flawlessly. We import excel tables with 250,000 rows with this and no trouble:
            DataTable dt = null;

            //Excel 2003
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                "Data Source=" + fileName + ";" +
                "Extended Properties=Excel 8.0;";
            OleDbConnection objConn = new OleDbConnection(connectionString);
            try
            {
                objConn.Open();
            }
            catch
            {
       		return null;
            }
  
            OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + parm.excelSheetName + "$]", bjConn);
            OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
            objAdapter1.SelectCommand = objCmdSelect;

            try
            {
                dt = new DataTable("ExcelTable");
                objAdapter1.Fill(dt);
                objConn.Close();
	    }
            catch (Exception e)
            {
                throw e;
            }
            return dt
>I am having a funny reaction when importing from Excel data into a dataset. This is the import function:
>
>
>        ' Import from Excel
>        Public Function ImportFromExcel() As Boolean
>            Dim lcConnection As String = ""
>
>            lcConnection = "provider=Microsoft.Jet.OLEDB.4.0; " + _
>             "data source='" + cSource + "'; Extended Properties=Excel 8.0;"
>
>            ' Assign the source directory
>            oConnection = New OleDbConnection(lcConnection)
>
>            ' Select the data from Sheet1 of the workbook
>            oDataAdapter = New OleDbDataAdapter("Select * From [" + cWorkbook + "$]", oConnection)
>
>            oDataSet = New DataSet
>            oDataAdapter.Fill(oDataSet)
>
>            ' Record count
>            nCount = oDataSet.Tables(0).Rows.Count
>
>            Return True
>        End Function
>
>
>My Excel sheet has three rows. In each of them, I have a field Extension. This field contains the values 124 and two blanks. The two blanks are being entered with a space. As the first value is 124, on that cell, the value is aligned right.
>
>But, when I import that, I end up with a null value being recognized on the first record where there is the value 124 in that column. If I delete the space values on the 2nd and 3rd rows, the next import will work ok and the 124 value will be recognized.
>
>To my understanding, this seems like a bug. I just don't know how to workaround that.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform