Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27083

VS 2010 Mixed Data in Datagridview from Excel

$
0
0
Ok here is the scenario.

My Excel File has 30k rows with mixed data. I am using this code to populate the DGV from Excel

Code:

Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
    Dim strCon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & txtFileName.Text &
                          "; Extended Properties=""Excel 12.0 XML;HDR=YES;IMEX=1;"""

    Dim cnn As New OleDbConnection(strCon)

    Dim oconn As New OleDbCommand("select * from [Sheet1$]", cnn)
    cnn.Open()

    Dim adp As New OleDbDataAdapter(oconn)
    Dim dt As New DataTable()
    adp.Fill(dt)

    dgvExcelData.SelectionMode = DataGridViewSelectionMode.FullRowSelect
    dgvExcelData.EditMode = DataGridViewEditMode.EditProgrammatically
    dgvExcelData.DataSource = dt
End Sub

The code works fine but DGV misses some data. On searching, I came across THIS post by jm. I did the registry fix and every thing was ok.

I know I can use the Open XML SDK but that is not the reason for this post. I am simply curious.

My Question

I want to know if there is a way where the user doesn't need to modify the registry and the above code works for xl2007+ Files (Not text/csv Files so not sure if schema.ini can be used for xlsx/xlsm)

Let me know if anyone wants a sample data?

OS: Win 7 64 Bit
VS 2010 Ultimate 64 Bit
MS Office(not that it matters since using ole): 32 bit

Viewing all articles
Browse latest Browse all 27083


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>