gamedesignteam

MOBILE GAMES, IPHONE APPLICATIONS, COMPUTER GAMES, GAME DEVELOPMENT TRAINING , http://www.gamedesignteam.com

  • game design team

    We have emerged as the leading online community for game development of all levels. Our expertise encases all facets for writing PC , Mobile and Online of 2D and 3D Gaming programming and applications development, for instance by using the latest 3D engines, scripting languages and animation techniques, our experienced and qualified team deals with all kind of requirements, whether it be a beginner's choice or an expert gaming action. Most importantly, we endeavor to offer compelling solution and eminent support to our growing community of prospective players and customers.

how do I open an excel file using vb.net ?

Posted by virtualinfocom On 1:26 AM 0 comments

Public Function ReadExcelIntoDataset(ByVal file As String) As Data.DataSet
    'Create the DataSet that will hold the data from the sheet
    Dim dsExcel As New Data.DataSet
    'First name sure the file exists
    If Not IO.File.Exists(file) Then
        MessageBox.Show("The file provided doesn't exist. Please check the name and try again")
    Else
        Try
            'Declare the variables needed for the reading of the Excel file
            Dim sOleDbString As New String("SELECT * FROM [sheet1$]")
            'Create our connection to the Excel sheet
            Dim cnExcel As New Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; data source='" & _
            file & " '; " & "Extended Properties=Excel 11.0;")
            'Create our command object
            Dim cmdExcel As New Data.OleDb.OleDbDataAdapter(sOleDbString, cnExcel)
            'Now we try to fill the DataSet with the data from the Excel file
            Try
                'Fill was successful
                cmdExcel.Fill(dsExcel)
                'Catch any errors that have occurred
            Catch ex As Exception 'Fill failed
                MessageBox.Show(ex.Message)
                dsExcel = Nothing
                'Finally close the connection
            Finally
                cnExcel.Close()
            End Try
            'Catch any errors that may have occurred
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            dsExcel = Nothing
        End Try
        Return dsExcel
    End If
End Function

Categories:

0 Response for the "how do I open an excel file using vb.net ?"

Post a Comment