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?
 
hindersalivaConnect With a Mentor Commented:
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
 
nutnutAuthor Commented:
Thanks very much great answer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.