I am trying to update a record at SQL Server by using parameters.
The VBA-code does not initiate an error, but the files at SQL Server Table are not updatet with worksheet data.
Can anybody see what I am doing wrong?
Description = Range("E42").Value
Mitigation = Range("E51").Value
Supervision = Range("E60").Value
Dim cmd As New ADODB.Command
Dim conn As ADODB.Connection
Dim prm As ADODB.Parameter
Dim strConn As String
'Developping
Server_Name = "localhost"
Database_Name = "AIM"
strConn = "Provider=SQLNCLI11;" & "Server=" & Server_Name & _
";Database=" & Database_Name & _
";Integrated Security=SSPI;"
Set conn = New ADODB.Connection
conn.Open strConn
Set cmd = New ADODB.Command
cmd.CommandText = "UPDATE dram.Register " & _
"SET Description = Description, " & _
"Mitigation = Mitigation, " & _
"Supervision = Supervision " & _
"WHERE DRAM_ID = DRAM_ID"
cmd.CommandType = adCmdText
cmd.ActiveConnection = conn
Set prm = cmd.CreateParameter("DRAM_ID", adVarChar, adParamInput, 255, CaseId)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("Description", adVarChar, adParamInput, 255, Description)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("Mitigation", adVarChar, adParamInput, 255, Mitigation)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("Supervision", adVarChar, adParamInput, 255, Supervision)
cmd.Parameters.Append prm
cmd.Execute
conn.Close
Thanks.
The VBA-code does not initiate an error, but the files at SQL Server Table are not updatet with worksheet data.
Can anybody see what I am doing wrong?
Description = Range("E42").Value
Mitigation = Range("E51").Value
Supervision = Range("E60").Value
Dim cmd As New ADODB.Command
Dim conn As ADODB.Connection
Dim prm As ADODB.Parameter
Dim strConn As String
'Developping
Server_Name = "localhost"
Database_Name = "AIM"
strConn = "Provider=SQLNCLI11;" & "Server=" & Server_Name & _
";Database=" & Database_Name & _
";Integrated Security=SSPI;"
Set conn = New ADODB.Connection
conn.Open strConn
Set cmd = New ADODB.Command
cmd.CommandText = "UPDATE dram.Register " & _
"SET Description = Description, " & _
"Mitigation = Mitigation, " & _
"Supervision = Supervision " & _
"WHERE DRAM_ID = DRAM_ID"
cmd.CommandType = adCmdText
cmd.ActiveConnection = conn
Set prm = cmd.CreateParameter("DRAM_ID", adVarChar, adParamInput, 255, CaseId)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("Description", adVarChar, adParamInput, 255, Description)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("Mitigation", adVarChar, adParamInput, 255, Mitigation)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("Supervision", adVarChar, adParamInput, 255, Supervision)
cmd.Parameters.Append prm
cmd.Execute
conn.Close
Thanks.