Results 1 to 11 of 11

Thread: how to import excel data to data grid view vb 2010

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    90

    how to import excel data to data grid view vb 2010

    hi All ,

    I am creating a program that will import the data of excel files to my datagridview on my program.
    here is the code i search.

    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
    
                Dim MyConnection As System.Data.OleDb.OleDbConnection
                Dim dataset As System.Data.DataSet
                Dim myCommand As System.Data.OleDb.OleDbDataAdapter
                Dim path As String = "C:\\Users\\lb770017\\Documents\\test.xlsx"
    
                MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties 12.0;")
                myCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
                dataset = New System.Data.DataSet
                myCommand.Fill(dataset)
                DataGridView1.DataSource = dataset.Tables(0)
                MyConnection.Close()
            Catch ex As Exception
                MsgBox(ex.Message.ToString)
    
            End Try
        End Sub
    it throws an exception message that
    format of the initialization string does not conform to specification starting at index 88

    my excel file will only compose 1 column
    Name:  Capturedd.PNG
Views: 1095
Size:  9.1 KB

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to import excel data to data grid view vb 2010

    You don't ask questions in the CodeBank forum. I've asked the mods to move this thread. Please don't create a duplicate in the mean time.

    As for the question, I believe that that error message indicates an invalid connection string. Why do you have double slashes in your file path?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    90

    Re: how to import excel data to data grid view vb 2010

    aw sorry sir.

    i am using backslash so it should be double , but if i used forward slash must be single, base on the research i made.
    can you suggest what should be the correct connection string ?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to import excel data to data grid view vb 2010

    Quote Originally Posted by BONITO View Post
    i am using backslash so it should be double
    No, it shouldn't. You only need to use a double backslash in languages where the backslash is an escape character. VB is not such a language.

    Looking closer, I doubt that your Extended Properties attribute is valid either. I suggest that you visit www.connectionstrings.com to get the appropriate format.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    90

    Re: how to import excel data to data grid view vb 2010

    really helpful link thanks for that,
    but now i'm getting error ."COULD NOT FIND INSTALLABLE ISAM"
    what does it means ?

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: how to import excel data to data grid view vb 2010

    Thread moved from the 'CodeBank VB.Net' forum (which is for you to post working code examples, not questions) to the 'VB.Net' forum

    Quote Originally Posted by BONITO View Post
    but now i'm getting error ."COULD NOT FIND INSTALLABLE ISAM"
    what does it means ?
    It should mean either you spelt the provider name wrong, or the provider is not installed on the computer you are running it on.

    However, as it is ACE, if your program is 32-bit and you installed the 64-bit version of the provider, it also won't be found (the same applies for 64-bit app and 32-bit provider).

    Unfortunately the error can sometimes also mean there are errors in the other parts of the connection string.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to import excel data to data grid view vb 2010

    Based on what si said, please show us your connection string as it is now and also tell us:

    1. Is your version of Office 32-bit or 64-bit?
    2. What is the 'Target Platform' for your project?
    3. If the Target Platform is 'Any CPU', is the 'Prefer 32-bit' box checked?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    90

    Re: how to import excel data to data grid view vb 2010

    here is my new connection string.
    Code:
        MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\lb770017\Documents\test.xlsx';Extended Properties =' Excel 12.0 Xml;HDR=YES;IMEX=1';")
    1. my office is 2007 and im using 32bit os.
    2. x86

    Name:  Capture.jpg
Views: 1079
Size:  37.7 KB

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    90

    Re: how to import excel data to data grid view vb 2010

    here is my new connection string.
    Code:
        MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\lb770017\Documents\test.xlsx';Extended Properties =' Excel 12.0 Xml;HDR=YES;IMEX=1';")
    1. my office is 2007 and im using 32bit os.
    2. x86

    Name:  Capture.jpg
Views: 1079
Size:  37.7 KB

  10. #10
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: how to import excel data to data grid view vb 2010

    Hello,

    Take a look at the following code sample.

  11. #11
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: how to import excel data to data grid view vb 2010

    Hello,

    Take a look at the following code sample.

Tags for this Thread

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