Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7760247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:49:56+00:00 2026-06-01T13:49:56+00:00

Alright, I finally got this code to work after hours of toiling: Dim path

  • 0

Alright, I finally got this code to work after hours of toiling:

        Dim path As String = OpenFileDialog1.FileName
        Dim myDataset As New DataSet()
        Dim strConn = New OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=" & path & ";Extended Properties=""Excel 12.0;HDR=YES;IMEX=1""")
        Dim myData As New OleDb.OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
        myData.Fill(myDataset)
        DataGridView1.DataSource = myDataset.Tables(0).DefaultView

Now that I figured that out I was going to try and place the data in a specific location. On my application I have a datagridview set up with 4 columns. What I would like to do is put column A of the excel file under the 1st column of the datagridview and column C of the Excel File in the second column of the datagridview.

So replace:

    DataGridView1.DataSource = myDataset.Tables(0).DefaultView

with:

    DataGridView1.columns(0) = myDataset.Tables(0).columns(0)
    DataGridView1.columns(1) = myDataset.Tables(0).columns(2)

Obviously this doesnt work, and something tells me I might need a for loop to import the data, but I have never imported information from an Excel file before and to make it worse I have never worked with datagridviews before so I have no idea how to go about this.

I would like to do something like this if I could:

        For x = 1 To xldoc.rows.length - 1
            DataGridView1.Item(0, x).Value = CType(xlDoc.Cells(0, x + 1), Excel.Range).Text
        Next
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:49:57+00:00Added an answer on June 1, 2026 at 1:49 pm

    This ended up being way easier to import the data. Im posting this in case anyone else comes across this thread.

        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            xLApp = New Excel.Application
            xLBook = xLApp.Workbooks.Open(OpenFileDialog1.FileName)
            xLSheet = xLBook.Worksheets("Sheet1")
            For x = 1 To xLSheet.UsedRange.Rows.Count - 1
                DataGridView1.Rows.Add()
                DataGridView1.Item(0, x - 1).Value = xLSheet.Cells(1 + x, 1).value
                DataGridView1.Item(1, x - 1).Value = xLSheet.Cells(1 + x, xLSheet.UsedRange.Columns.Count).value
            Next
        End If
    

    Dont even bother with:

        Dim myDataset As New DataSet()
        Dim strConn = New OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=" & path & ";Extended Properties=""Excel 12.0;HDR=YES;IMEX=1""")
        Dim myData As New OleDb.OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright I've been working on this for hours now and can't figure out my
Alright, this is basic c++ here. I've got a class that is a Linear
Alright, after doing a ton of research and trying almost every managed CPP Redist
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, I know questions like this have probably been asked dozens of times, but
Consider this code: public void actionPerformed(ActionEvent e) { setEnabled(false); new SwingWorker<File, Void>() { private
Alright, i have read many different views on how to do this with no
Alright so this is a bizarre cross platform thing that I'm experiencing with text
Alright y'all. I am attempting to write a bit of code that places typographic
Alright I am practicing using cURL to login to different webservices. For this pariticular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.