Is it possible to use LINQ to "PUSH" data to SQL Server DB from an Excel Addin?

Hi I am trying to workout the best way to "push" data from an Excel Addin to a SQL Server.  The data in Excel is a predetermined and validated dataset (so I know it will insert fine).  I want to use an Excel Addin I am going to develop to insert the data to a predetermined SQL server table.  Would linq work to do this?  I so an tips would be appreciated.

Thanks in advance

Andrew
nutnutAsked:
Who is Participating?

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

x
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.

hindersalivaCommented:
This is how I do it with VBA, ADO and SQL. You may need to loop over the rows of data you want to insert in the Sub PutData(). And you need to go to Tools>References and enable Microsoft ActiveX Data Objects.

Public objConn As New ADODB.Connection
Sub DBConnectionSQL()

    If CBool(objConn.State And adStateOpen) Then objConn.Close

    Dim szConnect As String

    szConnect = [PUT YOUR SQL SERVER CONNECTION STRING HERE] <<<<<<<<<<<<<
    
    objConn.CommandTimeout = 120
    objConn.ConnectionString = szConnect
    objConn.Open

End Sub

Sub DBConnectionClose()
 
    If CBool(objConn.State And adStateOpen) Then objConn.Close
    Set objConn = Nothing
 
End Sub

Sub PutData()

    Dim rsData As ADODB.Recordset
    Dim sSQL As String
    
    Call DBConnectionSQL

    sSQL = [PUT YOUR INSERT SQL STATEMENT HERE] <<<<<<<<<<<<<<<<<<<<<<<<

    'run the query
    Set rsData = New ADODB.Recordset
    rsData.Open sSQL, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText

    Call DBConnectionClose

End Sub

Open in new window

0

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
nutnutAuthor Commented:
Thanks very much great answer
0
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
SQL

From novice to tech pro — start learning today.