Excel Dataset to SQL Table


I want to extract data from excel sheet then pass it to SQL table
I am trying to pass the excel data to Dataset and the the same DS insert it to SQL i attached my code.
I am getting some errors in the insert like null errors i this my DS is not correct.


'tomar datos de excel
        Dim xlWBook = CType(Globals.ThisAddIn.Application.ActiveWorkbook, excel.Workbook).GetVstoObject()
        Dim worksheet = CType(Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets(1),  _
        Dim cnExcel As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\libro1.xlsx;" & _
"Extended Properties=Excel 8.0;")

        Dim oDa As New OleDbDataAdapter
        Dim oDs As New Data.DataSet
        Dim oCmd As New OleDbCommand

        oCmd.CommandText = "SELECT * FROM cte"
        oCmd.Connection = cnExcel

        oDa.SelectCommand = oCmd

        oDa.Fill(oDs, "Clientes2")

        Dim rrrrr = oDs.Tables(0).Columns

            'Insertar en sql
            Dim sConnectionString As String
            sConnectionString = "Password=123;User ID=sa;" & _
                                "Initial Catalog=avi2;" & _
                                "Data Source=(local)"

            Dim objConn As New SqlConnection(sConnectionString)

            ' Create an instance of a DataAdapter.
            Dim daAuthors As New SqlDataAdapter("select * from clientes2", objConn)
            daAuthors.Fill(oDs, "Clientes2")
            daAuthors.FillSchema(oDs, Data.SchemaType.Mapped, "Clientes2")

            Dim objCommandBuilder As New SqlCommandBuilder(daAuthors)
            Dim ins = objCommandBuilder.GetInsertCommand
            daAuthors.Update(oDs, "clientes2")

        Catch ex As Exception

        End Try

        Dim rrr = worksheet.ListObjects.Item(1).GetVstoObject.Range.Name.ToString
        Dim com As New Data.OleDb.OleDbCommand("SELECT * FROM [Tabla_DatosExternos_1]", cnExcel)
        Catch ex As Exception
        End Try

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.