Results 1 to 9 of 9

Thread: Mixed Data in Datagridview from Excel

Threaded View

  1. #1

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Post Mixed Data in Datagridview from Excel

    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
    Last edited by Siddharth Rout; Apr 27th, 2013 at 04:11 AM. Reason: Added Prefix
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width