Export The data from Excel to Sequel Database

     

     

    Public Con As New ADODB.Connection, InputSh As Worksheet

    Sub ExportTheDataFromExcelToSQLDatabase()
    Establish_connection_With_SQLDB
    Con.Execute "Create table Sales (Period Date,Item varchar(15), Qty int, Location varchar(11))"
    Set InputSh = ThisWorkbook.Sheets("InputData")

    Dim R As Integer, Period As Date, Item As String, Qty As Integer, Location As String

    For R = 2 To InputSh.Range("A" & Rows.Count).End(xlUp).Row
    Period = InputSh.Cells(R, 1).Value
    Item = InputSh.Cells(R, 2).Value
    Qty = InputSh.Cells(R, 3).Value
    Location = InputSh.Cells(R, 4).Value
    Con.Execute "insert into Sales values ('" & Period & "', '" & Item & "'," & Qty & ",'" & Location & "')"
    Next
    Con.Close
    MsgBox "Hi Created The Table"
    End Sub



    Function Establish_connection_With_SQLDB()
    Dim ConnectionString As String
    ConnectionString = "Provider=SQLOLEDB;Data Source=PAVANKUMAR-PC;Initial Catalog=ExcelToSequel;Integrated Security=SSPI"
    Con.Open ConnectionString
    End Function

    Download The Workbook

     

  • Part 1 : Export The Data from Excel to SQL
  • Part 2 : Create Stored Procedure in Excel
  • Part 3 : Create Stored Procedure in Excel by Creating Variables
  •