Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. VBA Excel to SQL Server

VBA Excel to SQL Server

Scheduled Pinned Locked Moved Visual Basic
databasequestionsql-serversysadmin
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paulanthony
    wrote on last edited by
    #1

    Hi everyone - im trying to develop a solution whereby an existing excel spreadsheet gets submitted to an online SQL server database. The excel sheet is flat one dimensional and without formula. I have currently got all the information from the sheet into an array...my question is how to get the information into sql server from VBA. Can I use something like the following.. Dim DB As DAO.Database Set DB = DBEngine.OpenDatabase("server=localhost;database=blah") or do i need to implement webservices...next question is can a webservice handle an array as a parameter or do i need to rethink my logic at the spreadsheet level. I have pulled code snippets from google, and there seems to have been so many different providers database engines / references needed that im completely confused. What should i be using with Excel 2002 - what is the most stable db engine.

    M 1 Reply Last reply
    0
    • P paulanthony

      Hi everyone - im trying to develop a solution whereby an existing excel spreadsheet gets submitted to an online SQL server database. The excel sheet is flat one dimensional and without formula. I have currently got all the information from the sheet into an array...my question is how to get the information into sql server from VBA. Can I use something like the following.. Dim DB As DAO.Database Set DB = DBEngine.OpenDatabase("server=localhost;database=blah") or do i need to implement webservices...next question is can a webservice handle an array as a parameter or do i need to rethink my logic at the spreadsheet level. I have pulled code snippets from google, and there seems to have been so many different providers database engines / references needed that im completely confused. What should i be using with Excel 2002 - what is the most stable db engine.

      M Offline
      M Offline
      Mandar Patankar
      wrote on last edited by
      #2

      'you may need to add refrences for this to work look ADO library 'DataBase Connection parameters Public stConn As String 'Connection String Public Cnt As New ADODB.Connection 'Connection Object public StConn as String stConn = "Provider=sqloledb;" & _ "Data Source=ServerName;" & _ "Initial Catalog=Database;" & _ "User Id=sa;" & _ "Password=yourpassword;" Cnt.OPEN strconn Qry_str = "your Query Insert,Update,Delete;" Cnt.Execute Qry_str Mandar Patankar Microsoft Certified professional

      P 1 Reply Last reply
      0
      • M Mandar Patankar

        'you may need to add refrences for this to work look ADO library 'DataBase Connection parameters Public stConn As String 'Connection String Public Cnt As New ADODB.Connection 'Connection Object public StConn as String stConn = "Provider=sqloledb;" & _ "Data Source=ServerName;" & _ "Initial Catalog=Database;" & _ "User Id=sa;" & _ "Password=yourpassword;" Cnt.OPEN strconn Qry_str = "your Query Insert,Update,Delete;" Cnt.Execute Qry_str Mandar Patankar Microsoft Certified professional

        P Offline
        P Offline
        paulanthony
        wrote on last edited by
        #3

        Thanks for the reply Mandar Dim strConnection, Password, User, InitialC, Source Source = "PAULANT" 'Your server name User = "sa" 'The SQL user you want to use (probably 'sa') Password = "blah" 'The password for the previously defined User InitialC = "blah" 'The database you wish to maintain strConnection = "Provider=SQLOLEDB;Persist Security Info=False;Password=" & Password & ";User ID=" & User & ";Initial Catalog=" & InitialC & ";Data Source=" & Source Set objCommand = New ADODB.Command objCommand.ActiveConnection = strConnection ''' Load the SQL string into the Command object. objCommand.CommandText = "INSERT INTO tbl_register (fld_name) Values ('test')" ''' Execute the SQL statement. objCommand.Execute - This works - but using an IP Address doesn't work....I want to perform this command with a remote SQL Server

        U 1 Reply Last reply
        0
        • P paulanthony

          Thanks for the reply Mandar Dim strConnection, Password, User, InitialC, Source Source = "PAULANT" 'Your server name User = "sa" 'The SQL user you want to use (probably 'sa') Password = "blah" 'The password for the previously defined User InitialC = "blah" 'The database you wish to maintain strConnection = "Provider=SQLOLEDB;Persist Security Info=False;Password=" & Password & ";User ID=" & User & ";Initial Catalog=" & InitialC & ";Data Source=" & Source Set objCommand = New ADODB.Command objCommand.ActiveConnection = strConnection ''' Load the SQL string into the Command object. objCommand.CommandText = "INSERT INTO tbl_register (fld_name) Values ('test')" ''' Execute the SQL statement. objCommand.Execute - This works - but using an IP Address doesn't work....I want to perform this command with a remote SQL Server

          U Offline
          U Offline
          ulchris
          wrote on last edited by
          #4

          Add another parameter in your connect string: "SERVER=999.999.999.999;" Like so - Dim strConnection, Password, User, InitialC, Source, Server Server = "999.999.999.999" 'Set your own IP here Source = "PAULANT" 'Your server name User = "sa" 'The SQL user you want to use (probably 'sa') Password = "blah" 'The password for the previously defined User InitialC = "blah" 'The database you wish to maintain strConnection = "Provider=SQLOLEDB;Server=" & Server & ";Persist Security Info=False;Password=" & Password & ";User ID=" & User & ";Initial Catalog=" & InitialC & ";Data Source=" & Source Goodluck! Cprompt

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups