To execute an updategram, use this code:
Public Function ExecuteUpdategram(ByVal empidString As String, ByVal _
lastnameString As String) As String
Dim cmd As New ADODB.Command
Dim conn As New ADODB.Connection
Dim strmIn As New ADODB.Stream
Dim strmOut As New ADODB.Stream
Dim InputEmpID As String
Dim InputLastName As String
InputEmpID = empidString '"4"
InputLastName = lastnameString '"Peacock"
' Open a connection to the SQL Server.
conn.Provider = "SQLOLEDB"
conn.Open "server=(local); database=Northwind; uid=sa; "
Set cmd.ActiveConnection = conn
' Build the command string in the form of an XML template.
SQLxml = ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & " "
SQLxml = SQLxml & " "
SQLxml = SQLxml & ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & ""
SQLxml = SQLxml & "select top 2 FirstName, LastName FROM Employees FOR XML AUTO "
SQLxml = SQLxml & ""
' Set the command dialect to XML.
cmd.Dialect = "{5d531cb2-e6ed-11d2-b252-00c04f681b71}"
' Open the command stream and write our template to it.
strmIn.Open
strmIn.WriteText SQLxml
strmIn.Position = 0
Set cmd.CommandStream = strmIn
' Execute the command, open the return stream, and read the result.
strmOut.Open
strmOut.LineSeparator = adCRLF
cmd.NamedParameters = True
cmd.Parameters.Append cmd.CreateParameter("@EmployeeID", adBSTR, adParamInput, 1, InputEmpID)
cmd.Parameters.Append cmd.CreateParameter("@LastName", adBSTR, adParamInput, 7, InputLastName)
cmd.Properties("Output Stream").Value = strmOut
cmd.Execute , , adExecuteStream
strmOut.Position = 0
'Debug.Print strmOut.ReadText
ExecuteUpdategram = strmOut.ReadText
End Function
This code came from the
Microsoft web site.
|