Q:

Update SQL database through excel VBA

First off I understand the process of having a user update a db via excel runs alot of risks, I appreciate any advise against this method but lets speculate that I have the perfect user who never makes mistakes :)
So firstly I've managed to access a stored procedure via vba in excel to pull data based on a parameter in a particular cell. Now if I wanted to update these fields how would I go about doing this?
My first suggestion would be to create a stored procedure that updates based on all the fields in spreadsheet. If this is the right avenue to follow how would I loop through all the rows?
Any other suggestions people could offer would be greatly appreciated.

A:

Some notes on updating SQL Server. This [ODBC;FileDSN=z:\docs\test.dsn] can be any valid connection string.
Dim cn As Object,  rs As Object
Dim scn As String, sSQL As String, sFile As String

    sFile = ActiveWorkbook.FullName

    scn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sFile _
        & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

    ''Late binding, so no reference is needed

    Set cn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    cn.Open scn

    sSQL = "SELECT * INTO [ODBC;FileDSN=z:\docs\test.dsn].FromXL " _
         & "FROM [Sheet8$]"
    cn.Execute sSQL, recs
    Debug.Print recs

    sSQL = "INSERT INTO [ODBC;FileDSN=z:\docs\test.dsn].FromXL " _
         & "SELECT * FROM [Sheet8$]"
    cn.Execute sSQL, recs
    Debug.Print recs

    sSQL = "UPDATE [ODBC;FileDSN=z:\docs\test.dsn].FromXL x " _
         & "INNER JOIN [Sheet8$] w " _
         & "ON x.ID = w.ID SET x.Field =w.field"
    cn.Execute sSQL, recs
    Debug.Print recs

    rs.Open "SELECT * FROM [ODBC;FileDSN=z:\docs\test.dsn].FromXL", cn
    Debug.Print rs.GetString

