How to select just first column in Excel sheet with DataSet

Posted on 2006-04-20
Last Modified: 2008-02-01
        Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & Session("fn") & ";" & _
        "Extended Properties=""Excel 8.0;"""

        Dim myData As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
        myData.TableMappings.Add("Table", "ExcelTest")
        Dim myDataset As New DataSet
        myData.Fill(myDataset, "table1")

How can I just select the first column in the EXCEL sheet instead of all (*),
like:  ("SELECT  first_column  FROM [Sheet1$]", strConn)
Question by:MikeMCSD
    LVL 34

    Accepted Solution

    Does the first row contain the Column Names?

    If not, use this connection:

    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & Session("fn") & ";" & _
            "Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""

    "SELECT F1 FROM [Sheet1$]", strConn

    LVL 16

    Author Comment

    thanks Dave,
    I don't have a column name for the first row.
    What does the "F1" do?
    The code worked, but it also selected "F1" as the first row
    when I put it in a datagrid for testing.  It also selects a bunch of
    blanks row after the last row and I don't know how to stop it from
    doing that.
    LVL 34

    Expert Comment

    I'm not too sure about ADO .Net, but with ADO if you use HDR=No, then the column names are defaulted to F1 for A, F2 for B etc...

    What does your Excel sheet look like?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now