luisdogg13
luisdogg13

Reputation: 75

Export data to SQL Server from Visual Studio

I am creating a Visual Studio Macro and I want it to take the data it is generating and export it to SQL. I can't seem to find a good way to connect to a database from Visual Studio's VBA. Does anyone know of a good way to do this? I am running Visual Studio 2008 and SQL Server 2008.

Thanks for any help

Upvotes: 1

Views: 556

Answers (1)

TcKs
TcKs

Reputation: 26632

Add referenco to "System.Data.dll" and then write to module:

Public Sub TestSql()
    Dim cnn As New System.Data.SqlClient.SqlConnection("your connectionstring")
    Dim cmd As System.Data.SqlClient.SqlCommand = cnn.CreateCommand()
    cmd.CommandText = "INSERT INTO [MyTable] ( MyColumn ) VALUES ( @MyColumn )"
    cmd.Parameters.AddWithValue("@MyColumn", "Hello World!")
    cnn.Open()
    cmd.ExecuteNonQuery()
    cnn.Close()
End Sub

Upvotes: 2

Related Questions