views:

115

answers:

1

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

+2  A: 

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
TcKs
Thank you very much! Looks like that is working great!
luisdogg13
If it work, maybe I deserve upvote and/or accept answer ;)
TcKs
Sorry about that. Thought I did that before. I would upvote, but I'm new to stackoverflow
luisdogg13